virt_test\Scripts\python.exe testrunner/runner.py --logfile=testrun.log --config=pypy/testrunner_cfg.py --config=~/machine_cfg.py --root=pypy --timeout=4000
in dir d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build (timeout 4000 secs)
watching logfiles {'pytestLog': 'testrun.log'}
argv: ['virt_test\\Scripts\\python.exe', 'testrunner/runner.py', '--logfile=testrun.log', '--config=pypy/testrunner_cfg.py', '--config=~/machine_cfg.py', '--root=pypy', '--timeout=4000']
environment:
ALLUSERSPROFILE=C:\ProgramData
APPDATA=C:\Users\matti\AppData\Roaming
ASL.LOG=Destination=file
CHOCOLATEYINSTALL=C:\ProgramData\chocolatey
CHOCOLATEYLASTPATHUPDATE=133185086718935289
CHOCOLATEYTOOLSLOCATION=C:\tools
CLINK_DIR=C:\Program Files (x86)\clink\0.4.9
COMMONPROGRAMFILES=C:\Program Files (x86)\Common Files
COMMONPROGRAMFILES(X86)=C:\Program Files (x86)\Common Files
COMMONPROGRAMW6432=C:\Program Files\Common Files
COMPUTERNAME=DESKTOP-RYZEN
COMSPEC=C:\WINDOWS\system32\cmd.exe
CONDA_BAT=d:\miniconda\condabin\conda.bat
CONDA_EXE=d:\miniconda\Scripts\conda.exe
CONDA_SHLVL=0
CUDA_PATH=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.7
CUDA_PATH_V11_7=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.7
DRIVERDATA=C:\Windows\System32\Drivers\DriverData
LOCALAPPDATA=C:\Users\matti\AppData\Local
NUMBER_OF_PROCESSORS=2
NVTOOLSEXT_PATH=C:\Program Files\NVIDIA Corporation\NvToolsExt\
OS=Windows_NT
PATH=d:\CPython27\lib\site-packages\pywin32_system32;d:\pypy_stuff\pypy\externals\bin;D:\CPython27;D:\pypy_stuff\pypy2.7-v7.3.18\Scripts;D:\pypy_stuff\pypy2.7-v7.3.18;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\TortoiseHg\;C:\Program Files\Git\cmd;C:\ProgramData\chocolatey\bin;C:\WINDOWS\System32\OpenSSH
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
PROCESSOR_ARCHITECTURE=x86
PROCESSOR_ARCHITEW6432=AMD64
PROCESSOR_IDENTIFIER=AMD64 Family 23 Model 113 Stepping 0, AuthenticAMD
PROCESSOR_LEVEL=23
PROCESSOR_REVISION=7100
PROGRAMDATA=C:\ProgramData
PROGRAMFILES=C:\Program Files (x86)
PROGRAMFILES(X86)=C:\Program Files (x86)
PROGRAMW6432=C:\Program Files
PROMPT=$P$G
PSMODULEPATH=%ProgramFiles%\WindowsPowerShell\Modules;C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules
PUBLIC=C:\Users\Public
PWD=d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build
PYPYCHERRYPICK=
PYPY_ENABLE_WINCONSOLEIO=1
PYTEST_XDIST_AUTO_NUM_WORKERS=4
PYTHONPATH=.;
RTOOLS40_HOME=C:\rtools40
RTOOLS43_HOME=C:\rtools43
RTOOLS44_HOME=C:\rtools44
SYSTEMDRIVE=C:
SYSTEMROOT=C:\WINDOWS
TEMP=D:\SystemTemp
TMP=D:\SystemTemp
TMPDIR=d:\systemtemp\pytest
USERDOMAIN=DESKTOP-RYZEN
USERNAME=matti
USERPROFILE=C:\Users\matti
VS140COMNTOOLS=C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\
WINDIR=C:\WINDOWS
using PTY: False
using config pypy/testrunner_cfg.py
using config C:\Users\matti/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
++ 05:31:14 starting config/test [1 started in total]
++ 05:31:14 starting interpreter/astcompiler/test [2 started in total]
++ 05:31:14 starting interpreter/pyparser/test [3 started in total]
++ 05:31:14 starting interpreter/test [4 started in total]
__ config/test [1 done in total, somefailed=False] ____________________________
============================= test session starts =============================
platform win32 -- Python 2.7.18[pypy-7.3.18-alpha], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('d:\\pypy_stuff\\buildbot64\\slave\\own-win-x86-64\\build\\pypy\\.hypothesis\\examples')
pytest-2.9.2 from d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pytest.pyc
rootdir: d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 162 items / 1 skipped
config\test\test_pypyoption.py ..................................................................................................................................................................
=================== 162 passed, 1 skipped in 53.97 seconds ====================
++ 05:32:13 starting module/__builtin__/test [5 started in total]
__ interpreter/pyparser/test [2 done in total, somefailed=False] ______________
============================= test session starts =============================
platform win32 -- Python 2.7.18[pypy-7.3.18-alpha], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('d:\\pypy_stuff\\buildbot64\\slave\\own-win-x86-64\\build\\pypy\\.hypothesis\\examples')
pytest-2.9.2 from d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pytest.pyc
rootdir: d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build, inifile: pytest.ini
plugins: hypothesis-4.39.3
[platform:msg] Updated environment with vsver 160, using x64 True
[platform:msg] Updated environment with vsver 160, using x64 True
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 173.52 seconds =========================
++ 05:34:10 starting module/__pypy__/test [6 started in total]
__ interpreter/astcompiler/test [3 done in total, somefailed=False] ___________
============================= test session starts =============================
platform win32 -- Python 2.7.18[pypy-7.3.18-alpha], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('d:\\pypy_stuff\\buildbot64\\slave\\own-win-x86-64\\build\\pypy\\.hypothesis\\examples')
pytest-2.9.2 from d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pytest.py
rootdir: d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build, inifile: pytest.ini
plugins: hypothesis-4.39.3
[platform:msg] Updated environment with vsver 160, using x64 True
[platform:msg] Updated environment with vsver 160, using x64 True
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 278.78 seconds ========================
++ 05:35:59 starting module/_abc/test [7 started in total]
__ module/__builtin__/test [4 done in total, somefailed=False] ________________
============================= test session starts =============================
platform win32 -- Python 2.7.18[pypy-7.3.18-alpha], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('d:\\pypy_stuff\\buildbot64\\slave\\own-win-x86-64\\build\\pypy\\.hypothesis\\examples')
pytest-2.9.2 from d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pytest.pyc
rootdir: d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build, inifile: pytest.ini
plugins: hypothesis-4.39.3
[platform:msg] Updated environment with vsver 160, using x64 True
[platform:msg] Updated environment with vsver 160, using x64 True
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 252.73 seconds ===================
++ 05:36:30 starting module/_ast/test [8 started in total]
__ module/__pypy__/test [5 done in total, somefailed=True] ____________________
============================= test session starts =============================
platform win32 -- Python 2.7.18[pypy-7.3.18-alpha], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('d:\\pypy_stuff\\buildbot64\\slave\\own-win-x86-64\\build\\pypy\\.hypothesis\\examples')
pytest-2.9.2 from d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pytest.pyc
rootdir: d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build, inifile: pytest.ini
plugins: hypothesis-4.39.3
[platform:msg] Updated environment with vsver 160, using x64 True
[platform:msg] Updated environment with vsver 160, using x64 True
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 ..........
module\__pypy__\test\test_newmemoryview.py ........
module\__pypy__\test\test_os.py F
module\__pypy__\test\test_signal.py ..sss
module\__pypy__\test\test_special.py ............s.
================================== FAILURES ===================================
_________________________ AppTestOs.test_real_getenv __________________________
self = <pypy.interpreter.typedef.W_ObjectObjectUserDictWeakrefable object at 0x0000020184f5e1a8>
def test_real_getenv(self):
import __pypy__.os
import os
key = 'UNLIKELY_SET'
assert key not in os.environ
os.putenv(key, '42')
# this one skips Python cache
> assert __pypy__.os.real_getenv(key) == '42'
E (application-level) AssertionError
[d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pypy\module\__pypy__\test\test_os.py:4]:9: AssertionError
=========================== short test summary info ===========================
FAIL module\__pypy__\test\test_os.py::AppTestOs::()::test_real_getenv
============== 1 failed, 78 passed, 4 skipped in 184.86 seconds ===============
++ 05:37:22 starting module/_cffi_backend/test [9 started in total]
__ module/_abc/test [6 done in total, somefailed=False] _______________________
============================= test session starts =============================
platform win32 -- Python 2.7.18[pypy-7.3.18-alpha], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('d:\\pypy_stuff\\buildbot64\\slave\\own-win-x86-64\\build\\pypy\\.hypothesis\\examples')
pytest-2.9.2 from d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pytest.pyc
rootdir: d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build, inifile: pytest.ini
plugins: hypothesis-4.39.3
[platform:msg] Updated environment with vsver 160, using x64 True
[platform:msg] Updated environment with vsver 160, using x64 True
collected 6 items
module\_abc\test\apptest_abc.py ...
module\_abc\test\test_abc.py ...
========================= 6 passed in 100.61 seconds ==========================
++ 05:37:43 starting module/_codecs/test [10 started in total]
__ module/_ast/test [7 done in total, somefailed=False] _______________________
============================= test session starts =============================
platform win32 -- Python 2.7.18[pypy-7.3.18-alpha], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('d:\\pypy_stuff\\buildbot64\\slave\\own-win-x86-64\\build\\pypy\\.hypothesis\\examples')
pytest-2.9.2 from d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pytest.pyc
rootdir: d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build, inifile: pytest.ini
plugins: hypothesis-4.39.3
[platform:msg] Updated environment with vsver 160, using x64 True
[platform:msg] Updated environment with vsver 160, using x64 True
collected 57 items
module\_ast\test\apptest_ast.py ...
module\_ast\test\test_ast.py ......................................................
========================= 57 passed in 145.98 seconds =========================
++ 05:39:04 starting module/_collections/test [11 started in total]
__ interpreter/test [8 done in total, somefailed=True] ________________________
============================= test session starts =============================
platform win32 -- Python 2.7.18[pypy-7.3.18-alpha], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('d:\\pypy_stuff\\buildbot64\\slave\\own-win-x86-64\\build\\pypy\\.hypothesis\\examples')
pytest-2.9.2 from d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pytest.pyc
rootdir: d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build, inifile: pytest.ini
plugins: hypothesis-4.39.3
[platform:msg] Updated environment with vsver 160, using x64 True
[platform:msg] Updated environment with vsver 160, using x64 True
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 ......F.
interpreter\test\apptest_unraisable.py ....
interpreter\test\apptest_with_leak.py .........
interpreter\test\test_app_main.py sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss...
interpreter\test\test_appinterp.py .............
interpreter\test\test_argument.py ................................................
interpreter\test\test_buffer.py ...
interpreter\test\test_cellfamily.py .......
interpreter\test\test_code.py ............
interpreter\test\test_compiler.py .........
interpreter\test\test_error.py ..............
interpreter\test\test_exceptcomp.py .........
interpreter\test\test_executioncontext.py ................
interpreter\test\test_extmodules.py .
interpreter\test\test_fsencode.py F..
interpreter\test\test_function.py .............
interpreter\test\test_gateway.py .........................................ss.........................
interpreter\test\test_generator.py .
interpreter\test\test_interpreter.py .................................................
interpreter\test\test_location.py ..........
interpreter\test\test_main.py .....
interpreter\test\test_mixedmodule.py ......
interpreter\test\test_module.py ..................
interpreter\test\test_monitoring.py .......
interpreter\test\test_objspace.py .............................................
interpreter\test\test_pycode.py ..
interpreter\test\test_pyframe.py ................................
interpreter\test\test_reverse_debugging.py ..
interpreter\test\test_special.py ...
interpreter\test\test_syntax.py .....................
interpreter\test\test_targetpypy.py ..
interpreter\test\test_typedef.py ...................
interpreter\test\test_unicodehelper.py ..........
interpreter\test\test_zpy.py ssssssss
interpreter\test\test_zzpickle_and_slow.py s.....s..s..sss........ss...s.
================================== FAILURES ===================================
__________________________ test_colors_in_traceback ___________________________
def test_colors_in_traceback():
import os
def division_by_zero(a, b):
return (
a + b / 0 # abc
)
old_value = os.environ.get('FORCE_COLOR', None)
os.environ['FORCE_COLOR'] = '1'
try:
from _colorize import can_colorize, ANSIColors
> assert can_colorize()
E (application-level) AssertionError: assert False
E + where False = <function can_colorize at 0x000001cc5783e1e0>()
interpreter\test\apptest_traceback.py:177: AssertionError
_____________________ TestFSEncode.test_fsencode_fsdecode _____________________
self = <pypy.interpreter.test.test_fsencode.TestFSEncode instance at 0x000001cc5d988fa0>
def test_fsencode_fsdecode(self):
space = self.space
strs = [u"/home/bar/baz", u"c:\\"]
if self.special_char:
strs.append(self.special_char)
for st in strs:
# check roundtrip
w_st = space.newtext(st.encode('utf8'), len(st))
w_enc = space.fsencode(w_st)
w_st2 = space.fsdecode(w_enc)
assert space.eq_w(w_st, w_st2)
> assert space.fsdecode_w(w_enc) == st
E assert '\xc3\xa4' == u'\xe4'
E - \xc3\xa4
E + \xe4
interpreter\test\test_fsencode.py:77: AssertionError
---------------------------- Captured stderr call -----------------------------
d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pypy\interpreter\test\test_fsencode.py:77: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
assert space.fsdecode_w(w_enc) == st
d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pypy\interpreter\test\test_fsencode.py:1: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
import sys
=========================== short test summary info ===========================
FAIL interpreter\test\apptest_traceback.py::test_colors_in_traceback
FAIL interpreter\test\test_fsencode.py::TestFSEncode::()::test_fsencode_fsdecode
============ 2 failed, 1278 passed, 109 skipped in 507.42 seconds =============
++ 05:39:45 starting module/_continuation/test [12 started in total]
__ module/_collections/test [9 done in total, somefailed=False] _______________
============================= test session starts =============================
platform win32 -- Python 2.7.18[pypy-7.3.18-alpha], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('d:\\pypy_stuff\\buildbot64\\slave\\own-win-x86-64\\build\\pypy\\.hypothesis\\examples')
pytest-2.9.2 from d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pytest.pyc
rootdir: d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build, inifile: pytest.ini
plugins: hypothesis-4.39.3
[platform:msg] Updated environment with vsver 160, using x64 True
[platform:msg] Updated environment with vsver 160, using x64 True
collected 66 items
module\_collections\test\apptest_defaultdict.py ..............
module\_collections\test\apptest_deque.py ..........................................
module\_collections\test\apptest_ordereddict.py ..........
========================= 66 passed in 104.91 seconds =========================
++ 05:40:55 starting module/_cppyy/test [13 started in total]
__ module/_cppyy/test [10 done in total, somefailed=False] ____________________
============================= test session starts =============================
platform win32 -- Python 2.7.18[pypy-7.3.18-alpha], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('d:\\pypy_stuff\\buildbot64\\slave\\own-win-x86-64\\build\\pypy\\.hypothesis\\examples')
pytest-2.9.2 from d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pytest.pyc
rootdir: d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 0 items
======================== no tests ran in 0.02 seconds =========================
++ 05:41:11 starting module/_csv/test [14 started in total]
__ module/_codecs/test [11 done in total, somefailed=True] ____________________
============================= test session starts =============================
platform win32 -- Python 2.7.18[pypy-7.3.18-alpha], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('d:\\pypy_stuff\\buildbot64\\slave\\own-win-x86-64\\build\\pypy\\.hypothesis\\examples')
pytest-2.9.2 from d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pytest.pyc
rootdir: d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build, inifile: pytest.ini
plugins: hypothesis-4.39.3
[platform:msg] Updated environment with vsver 160, using x64 True
[platform:msg] Updated environment with vsver 160, using x64 True
collected 99 items
module\_codecs\test\apptest_codecs.py ..
module\_codecs\test\test_codecs.py ............................................................................F......s......
module\_codecs\test\test_locale.py FFF...
module\_codecs\test\test_ztranslation.py .
================================== FAILURES ===================================
_____________________ AppTestPartialEvaluation.test_mbcs ______________________
self = <pypy.interpreter.typedef.W_ObjectObjectUserDictWeakrefable object at 0x000001a04df259f0>
def test_mbcs(self):
import sys
if sys.platform != 'win32':
return
# sanity test
from _codecs import mbcs_encode, mbcs_decode
toencode = u'caf\xe9', 'caf\xe9'
try:
# test for non-latin1 codepage, more general test needed
import winreg
key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE,
r'System\CurrentControlSet\Control\Nls\CodePage')
if winreg.QueryValueEx(key, 'ACP')[0] == u'1255': # non-latin1
toencode = u'caf\xbf',b'caf\xbf'
except:
assert False, 'cannot test mbcs on this windows system, check code page'
assert u'test'.encode('mbcs') == b'test'
> assert toencode[0].encode('mbcs') == toencode[1]
E (application-level) AssertionError
[d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pypy\module\_codecs\test\test_codecs.py:1412]:19: AssertionError
---------------------------- Captured stderr call -----------------------------
[d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pypy\module\_codecs\test\test_codecs.py:1412]:21: SyntaxWarning: invalid escape sequence '\e'
[d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pypy\module\_codecs\test\test_codecs.py:1412]:21: SyntaxWarning: invalid escape sequence '\e'
_____________________ TestLocaleCodec.test_encode_locale ______________________
self = <pypy.module._codecs.test.test_locale.TestLocaleCodec object at 0x000001a058c5f3d0>
def test_encode_locale(self):
self.setlocale("en_US.UTF-8")
for locale_encoder in (utf8_encode_locale_surrogateescape,
utf8_encode_locale_strict):
for val in u'foo', u' 日本', u'\U0001320C':
utf8 = val.encode('utf-8')
encoded = locale_encoder(utf8, len(val))
> assert encoded.decode('utf8') == val
E assert u'\u320c' == u'\U0001320c'
E - \u320c
E + \U0001320c
module\_codecs\test\test_locale.py:45: AssertionError
_______________ TestLocaleCodec.test_encode_locale_errorhandler _______________
self = <pypy.module._codecs.test.test_locale.TestLocaleCodec object at 0x000001a058e1b328>
def test_encode_locale_errorhandler(self):
self.setlocale("en_US.UTF-8")
locale_encoder = utf8_encode_locale_surrogateescape
utf8_encoder = self.getencoder('utf-8')
encode_error_handler = self.getstate().encode_error_handler
for val in u'foo\udc80bar', u'\udcff\U0001320C':
s = val.encode('utf8')
w_s = self.space.newtext(s)
expected = utf8_encoder(self.space, s, w_s, 'surrogateescape',
encode_error_handler)
utf8 = val.encode('utf-8')
> assert locale_encoder(utf8, len(val)) == expected
E assert '\xff\xe3\x88\x8c' == '\xff\xf0\x93\x88\x8c'
E - \xff\xe3\x88\x8c
E ? ^
E + \xff\xf0\x93\x88\x8c
E ? ^^^^^
module\_codecs\test\test_locale.py:58: AssertionError
_____________________ TestLocaleCodec.test_decode_locale ______________________
self = <pypy.module._codecs.test.test_locale.TestLocaleCodec object at 0x000001a057bb3c20>
def test_decode_locale(self):
self.setlocale("en_US.UTF-8")
utf8_decoder = self.getdecoder('utf-8')
for locale_decoder in (str_decode_locale_surrogateescape,
str_decode_locale_strict):
for val in 'foo', ' \xe6\x97\xa5\xe6\x9c\xac', '\xf0\x93\x88\x8c':
w_s = self.space.newbytes(val)
assert (locale_decoder(val) ==
utf8_decoder(self.space, val, w_s, 'strict',
> True, None)[:2])
E assert ('\xef\xbf\xbd', 1) == ('\xf0\x93\x88\x8c', 1)
E At index 0 diff: '\xef\xbf\xbd' != '\xf0\x93\x88\x8c'
E Use -v to get the full diff
module\_codecs\test\test_locale.py:69: AssertionError
=========================== short test summary info ===========================
FAIL module\_codecs\test\test_codecs.py::AppTestPartialEvaluation::()::test_mbcs
FAIL module\_codecs\test\test_locale.py::TestLocaleCodec::()::test_encode_locale
FAIL module\_codecs\test\test_locale.py::TestLocaleCodec::()::test_encode_locale_errorhandler
FAIL module\_codecs\test\test_locale.py::TestLocaleCodec::()::test_decode_locale
============== 4 failed, 94 passed, 1 skipped in 219.51 seconds ===============
++ 05:41:31 starting module/_demo/test [15 started in total]
__ module/_continuation/test [12 done in total, somefailed=False] _____________
============================= test session starts =============================
platform win32 -- Python 2.7.18[pypy-7.3.18-alpha], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('d:\\pypy_stuff\\buildbot64\\slave\\own-win-x86-64\\build\\pypy\\.hypothesis\\examples')
pytest-2.9.2 from d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pytest.pyc
rootdir: d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 32 items / 3 skipped
module\_continuation\test\test_generator.py ssss
module\_continuation\test\test_greenlet.py s.ssssss.sssssssssssssss.sss
=================== 3 passed, 32 skipped in 114.73 seconds ====================
++ 05:41:42 starting module/_hpy_universal/test/_vendored [16 started in total]
__ module/_hpy_universal/test/_vendored [13 done in total, somefailed=True] ___
[platform:msg] Updated environment with vsver 160, using x64 True
[platform:msg] Updated environment with vsver 160, using x64 True
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\_pytest\main.py", line 109, in wrap_session
INTERNALERROR> config.hook.pytest_sessionstart(session=session)
INTERNALERROR> File "d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\_pytest\vendored_packages\pluggy.py", line 724, in __call__
INTERNALERROR> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
INTERNALERROR> File "d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\_pytest\vendored_packages\pluggy.py", line 338, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR> File "d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\_pytest\vendored_packages\pluggy.py", line 333, in <lambda>
INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR> File "d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\_pytest\vendored_packages\pluggy.py", line 596, in execute
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pypy\module\_hpy_universal\test\conftest.py", line 145, in pytest_sessionstart
INTERNALERROR> from pypy.module._hpy_universal.test import support as _support
INTERNALERROR> File "d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pypy\module\_hpy_universal\test\support.py", line 6, in <module>
INTERNALERROR> from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase
INTERNALERROR> File "d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pypy\module\cpyext\test\test_cpyext.py", line 9, in <module>
INTERNALERROR> from pypy.module.cpyext import api
INTERNALERROR> File "d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pypy\module\cpyext\api.py", line 29, in <module>
INTERNALERROR> from pypy.interpreter.generator import GeneratorIterator
INTERNALERROR> File "d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pypy\interpreter\generator.py", line 3, in <module>
INTERNALERROR> from pypy.interpreter.pyopcode import SApplicationException, Yield
INTERNALERROR> File "d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pypy\interpreter\pyopcode.py", line 15, in <module>
INTERNALERROR> from pypy.interpreter import (
INTERNALERROR> File "d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pypy\interpreter\pyframe.py", line 22, in <module>
INTERNALERROR> from pypy.interpreter.pymonitoring import (
INTERNALERROR> File "d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pypy\interpreter\pymonitoring.py", line 5, in <module>
INTERNALERROR> from pypy.interpreter.typedef import TypeDef
INTERNALERROR> File "d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pypy\interpreter\typedef.py", line 572, in <module>
INTERNALERROR> from pypy.interpreter.pyframe import PyFrame
INTERNALERROR> ImportError: cannot import name 'PyFrame'
++ 05:41:50 starting module/_hpy_universal/test/pypy [17 started in total]
__ module/_hpy_universal/test/pypy [14 done in total, somefailed=True] ________
[platform:msg] Updated environment with vsver 160, using x64 True
[platform:msg] Updated environment with vsver 160, using x64 True
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\_pytest\main.py", line 109, in wrap_session
INTERNALERROR> config.hook.pytest_sessionstart(session=session)
INTERNALERROR> File "d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\_pytest\vendored_packages\pluggy.py", line 724, in __call__
INTERNALERROR> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
INTERNALERROR> File "d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\_pytest\vendored_packages\pluggy.py", line 338, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR> File "d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\_pytest\vendored_packages\pluggy.py", line 333, in <lambda>
INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR> File "d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\_pytest\vendored_packages\pluggy.py", line 596, in execute
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pypy\module\_hpy_universal\test\conftest.py", line 145, in pytest_sessionstart
INTERNALERROR> from pypy.module._hpy_universal.test import support as _support
INTERNALERROR> File "d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pypy\module\_hpy_universal\test\support.py", line 6, in <module>
INTERNALERROR> from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase
INTERNALERROR> File "d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pypy\module\cpyext\test\test_cpyext.py", line 9, in <module>
INTERNALERROR> from pypy.module.cpyext import api
INTERNALERROR> File "d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pypy\module\cpyext\api.py", line 29, in <module>
INTERNALERROR> from pypy.interpreter.generator import GeneratorIterator
INTERNALERROR> File "d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pypy\interpreter\generator.py", line 3, in <module>
INTERNALERROR> from pypy.interpreter.pyopcode import SApplicationException, Yield
INTERNALERROR> File "d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pypy\interpreter\pyopcode.py", line 15, in <module>
INTERNALERROR> from pypy.interpreter import (
INTERNALERROR> File "d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pypy\interpreter\pyframe.py", line 22, in <module>
INTERNALERROR> from pypy.interpreter.pymonitoring import (
INTERNALERROR> File "d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pypy\interpreter\pymonitoring.py", line 5, in <module>
INTERNALERROR> from pypy.interpreter.typedef import TypeDef
INTERNALERROR> File "d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pypy\interpreter\typedef.py", line 572, in <module>
INTERNALERROR> from pypy.interpreter.pyframe import PyFrame
INTERNALERROR> ImportError: cannot import name 'PyFrame'
++ 05:41:57 starting module/_io/test [18 started in total]
__ module/_demo/test [15 done in total, somefailed=False] _____________________
============================= test session starts =============================
platform win32 -- Python 2.7.18[pypy-7.3.18-alpha], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('d:\\pypy_stuff\\buildbot64\\slave\\own-win-x86-64\\build\\pypy\\.hypothesis\\examples')
pytest-2.9.2 from d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pytest.pyc
rootdir: d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 3 items
module\_demo\test\test_import.py ..
module\_demo\test\test_sieve.py .
========================== 3 passed in 41.81 seconds ==========================
++ 05:42:16 starting module/_jitlog/test [19 started in total]
__ module/_csv/test [16 done in total, somefailed=False] ______________________
============================= test session starts =============================
platform win32 -- Python 2.7.18[pypy-7.3.18-alpha], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('d:\\pypy_stuff\\buildbot64\\slave\\own-win-x86-64\\build\\pypy\\.hypothesis\\examples')
pytest-2.9.2 from d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pytest.pyc
rootdir: d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build, inifile: pytest.ini
plugins: hypothesis-4.39.3
[platform:msg] Updated environment with vsver 160, using x64 True
[platform:msg] Updated environment with vsver 160, using x64 True
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 85.34 seconds ==========================
++ 05:42:40 starting module/_locale/test [20 started in total]
__ module/_jitlog/test [17 done in total, somefailed=False] ___________________
============================= test session starts =============================
platform win32 -- Python 2.7.18[pypy-7.3.18-alpha], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('d:\\pypy_stuff\\buildbot64\\slave\\own-win-x86-64\\build\\pypy\\.hypothesis\\examples')
pytest-2.9.2 from d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pytest.pyc
rootdir: d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 1 items
module\_jitlog\test\test__jitlog.py s
========================= 1 skipped in 34.90 seconds ==========================
++ 05:42:55 starting module/_lsprof/test [21 started in total]
__ module/_locale/test [18 done in total, somefailed=False] ___________________
============================= test session starts =============================
platform win32 -- Python 2.7.18[pypy-7.3.18-alpha], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('d:\\pypy_stuff\\buildbot64\\slave\\own-win-x86-64\\build\\pypy\\.hypothesis\\examples')
pytest-2.9.2 from d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pytest.pyc
rootdir: d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 15 items
module\_locale\test\test_locale.py .......ss.ss.s.
==================== 10 passed, 5 skipped in 68.75 seconds ====================
++ 05:43:55 starting module/_md5/test [22 started in total]
__ module/_lsprof/test [19 done in total, somefailed=True] ____________________
============================= test session starts =============================
platform win32 -- Python 2.7.18[pypy-7.3.18-alpha], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('d:\\pypy_stuff\\buildbot64\\slave\\own-win-x86-64\\build\\pypy\\.hypothesis\\examples')
pytest-2.9.2 from d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pytest.pyc
rootdir: d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 6 items
module\_lsprof\test\test_cprofile.py .F..F.
================================== FAILURES ===================================
________________________ AppTestCProfile.test_builtins ________________________
self = <pypy.interpreter.typedef.W_ObjectObjectUserDictWeakrefable object at 0x0000024a181f5520>
def test_builtins(self):
import _lsprof
prof = _lsprof.Profiler()
lst = []
prof.enable()
lst.append(len(lst))
prof.disable()
stats = prof.getstats()
expected = (
"<built-in method builtins.len>",
"<method 'append' of 'list' objects>",
"<method 'disable' of '_lsprof.Profiler' objects>",
)
for entry in stats:
> assert entry.code in expected
E (application-level) AssertionError
[d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pypy\module\_lsprof\test\test_cprofile.py:13]:15: AssertionError
____________________ AppTestCProfile.test_scale_of_result _____________________
self = <pypy.interpreter.typedef.W_ObjectObjectUserDictWeakrefable object at 0x0000024a181f5520>
def test_scale_of_result(self):
import _lsprof, time
prof = _lsprof.Profiler()
def foo(n):
t = time.time()
while abs(t - time.time()) < 1.0:
pass # busy-wait for 1 second
def bar(n):
foo(n)
prof.enable()
bar(0)
prof.disable()
stats = prof.getstats()
entries = {}
for entry in stats:
entries[entry.code] = entry
efoo = entries[foo.__code__]
ebar = entries[bar.__code__]
> assert 0.9 < efoo.totaltime < 2.9
E (application-level) AssertionError
[d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pypy\module\_lsprof\test\test_cprofile.py:130]:19: AssertionError
=========================== short test summary info ===========================
FAIL module\_lsprof\test\test_cprofile.py::AppTestCProfile::()::test_builtins
FAIL module\_lsprof\test\test_cprofile.py::AppTestCProfile::()::test_scale_of_result
===================== 2 failed, 4 passed in 68.57 seconds =====================
++ 05:44:10 starting module/_minimal_curses/test [23 started in total]
__ module/_md5/test [20 done in total, somefailed=False] ______________________
============================= test session starts =============================
platform win32 -- Python 2.7.18[pypy-7.3.18-alpha], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('d:\\pypy_stuff\\buildbot64\\slave\\own-win-x86-64\\build\\pypy\\.hypothesis\\examples')
pytest-2.9.2 from d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pytest.pyc
rootdir: d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 8 items
module\_md5\test\test_md5.py ........
========================== 8 passed in 77.21 seconds ==========================
++ 05:45:17 starting module/_multibytecodec/test [24 started in total]
__ module/_minimal_curses/test [21 done in total, somefailed=False] ___________
============================= test session starts =============================
platform win32 -- Python 2.7.18[pypy-7.3.18-alpha], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('d:\\pypy_stuff\\buildbot64\\slave\\own-win-x86-64\\build\\pypy\\.hypothesis\\examples')
pytest-2.9.2 from d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pytest.pyc
rootdir: d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 6 items
[platform:msg] Updated environment with vsver 160, using x64 True
[platform:msg] Updated environment with vsver 160, using x64 True
module\_minimal_curses\test\test_curses.py ssssss
========================= 6 skipped in 122.86 seconds =========================
++ 05:46:15 starting module/_multiprocessing/test [25 started in total]
__ module/_io/test [22 done in total, somefailed=True] ________________________
============================= test session starts =============================
platform win32 -- Python 2.7.18[pypy-7.3.18-alpha], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('d:\\pypy_stuff\\buildbot64\\slave\\own-win-x86-64\\build\\pypy\\.hypothesis\\examples')
pytest-2.9.2 from d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pytest.pyc
rootdir: d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build, inifile: pytest.ini
plugins: hypothesis-4.39.3
[platform:msg] Updated environment with vsver 160, using x64 True
[platform:msg] Updated environment with vsver 160, using x64 True
collected 300 items
module\_io\test\apptest_bufferedio.py .
module\_io\test\apptest_bytesio.py .................
module\_io\test\apptest_io.py .......................F.....F..........F..
module\_io\test\apptest_stringio.py ...........................
module\_io\test\apptest_textio.py ..............................s..................
module\_io\test\test_bufferedio.py .....................ss......................ss........................ss................................
module\_io\test\test_fileio.py ..................s.................
module\_io\test\test_interp_textio.py ......FF.
module\_io\test\test_win32consoleio.py ......s......
================================== FAILURES ===================================
________________________________ test_telling _________________________________
tempfile = W_UnicodeObject('d:\\systemtemp\\pytest\\pytest-of-matti\\pytest-3242\\tempfile')
def test_telling(tempfile):
with _io.open(tempfile, "w+", encoding="utf8") as f:
p0 = f.tell()
f.write("\xff\n")
p1 = f.tell()
f.write("\xff\n")
p2 = f.tell()
f.seek(0)
assert p0 == 0
> assert p1 == 3
E (application-level) AssertionError: assert 4 == 3
module\_io\test\apptest_io.py:287: AssertionError
____________________________ test_warn_on_dealloc _____________________________
tempfile = W_UnicodeObject('d:\\systemtemp\\pytest\\pytest-of-matti\\pytest-3248\\tempfile')
def test_warn_on_dealloc(tempfile):
> _check_warn_on_dealloc(tempfile, 'wb', buffering=0)
module\_io\test\apptest_io.py:376:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
args = W_TupleObject(W_UnicodeObject('d:\\systemtemp\\pytest\\pytest-of-matti\\pytest-3248\\tempfile'), W_UnicodeObject('wb'))
kwargs = W_DictObject(<pypy.objspace.std.kwargsdict.KwargsDictStrategy object at 0x0000024f45497018>)
gc = <pypy.module.gc.moduledef.Module object at 0x0000024f44a3d398>
warnings = <pypy.interpreter.module.Module object at 0x0000024f4755b9b8>
f = <pypy.objspace.std.noneobject.W_NoneObject object at 0x0000024f42196a30>
r = W_UnicodeObject("<_io.FileIO name='d:\\\\systemtemp\\\\pytest\\\\pytest-of-matti\\\\pytest-3248\\\\tempfile' mode='wb' closefd=True>")
w = W_ListObject(<pypy.objspace.std.listobject.ObjectListStrategy object at 0x0000...reter.typedef.W_ObjectObjectUserDictWeakrefable object at 0x0000024f4f942218>])
@py_assert2 = <pypy.objspace.std.noneobject.W_NoneObject object at 0x0000024f42196a30>
@py_assert5 = W_UnicodeObject('{message : ResourceWarning("unclosed file <_io.FileIO name=\'...\pypy\\\\module\\\\_io\\\\test\\\\apptest_io.py\', lineno : 371, line : None}')
@py_assert4 = <pypy.objspace.std.noneobject.W_NoneObject object at 0x0000024f42196a30>
@py_format7 = W_UnicodeObject('"<_io.FileIO name=\'d:\\\\\\\\systemtemp\\\\\\\\pytest\\\\\\\...ne : None}\' = str(<warnings.WarningMessage object at 0x0000024f4f942218>)\n}')
@py_format9 = W_UnicodeObject('assert "<_io.FileIO name=\'d:\\\\\\\\systemtemp\\\\\\\\pytest...ne : None}\' = str(<warnings.WarningMessage object at 0x0000024f4f942218>)\n}')
def _check_warn_on_dealloc(*args, **kwargs):
import gc
import warnings
f = open(*args, **kwargs)
r = repr(f)
gc.collect()
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter('always')
f = None
gc.collect()
assert len(w) == 1, len(w)
> assert r in str(w[0])
E (application-level) AssertionError: assert "<_io.FileIO name='d:\\\\systemtemp\\\\pytest\\\\pytest-of-matti\\\\pytest-3248\\\\tempfile' mode='wb' closefd=True>" in '{message : ResourceWarning("unclosed file <_io.FileIO name=\'d:\\\\\\\\systemtemp\\\\\\\\pytest\\\\\\\\pytest-of-matti\\\\\\\\pytest-3248\\\\\\\\tempfile\' mode=\'wb\' closefd=True>"), category : \'ResourceWarning\', filename : \'d:\\\\pypy_stuff\\\\buildbot64\\\\slave\\\\own-win-x86-64\\\\build\\\\pypy\\\\module\\\\_io\\\\test\\\\apptest_io.py\', lineno : 371, line : None}'
E + where '{message : ResourceWarning("unclosed file <_io.FileIO name=\'d:\\\\\\\\systemtemp\\\\\\\\pytest\\\\\\\\pytest-of-matti\\\\\\\\pytest-3248\\\\\\\\tempfile\' mode=\'wb\' closefd=True>"), category : \'ResourceWarning\', filename : \'d:\\\\pypy_stuff\\\\buildbot64\\\\slave\\\\own-win-x86-64\\\\build\\\\pypy\\\\module\\\\_io\\\\test\\\\apptest_io.py\', lineno : 371, line : None}' = str(<warnings.WarningMessage object at 0x0000024f4f942218>)
module\_io\test\apptest_io.py:373: AssertionError
___________________________ test_tell_univnewlines ____________________________
tempfile = W_UnicodeObject('d:\\systemtemp\\pytest\\pytest-of-matti\\pytest-3257\\tempfile')
def test_tell_univnewlines(tempfile):
import io
import sys
NEWLINE = '\r\n'
with io.open(tempfile, "w") as fp:
fp.write(DATA_CRLF)
with io.open(tempfile, "r") as fp:
assert repr(fp.newlines) == repr(None)
data = fp.readline()
pos = fp.tell()
if "__pypy__" in sys.modules:
> assert repr(fp.newlines) == repr(NEWLINE)
E (application-level) AssertionError: assert "'\\r'" == "'\\r\\n'"
E + where "'\\r'" = repr('\r')
E + where '\r' = <_io.TextIOWrapper name='d:\\systemtemp\\pytest\\pytest-of-matti\\pytest-3257\\tempfile' mode='r' encoding='utf-8'>.newlines
E + and "'\\r\\n'" = repr('\r\n')
module\_io\test\apptest_io.py:559: AssertionError
__________________________________ test_tell __________________________________
space = StdObjSpace
@given(content=st_readline(characters=st.characters(blacklist_categories='C')))
> def test_tell(space, content):
module\_io\test\test_interp_textio.py:147:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
..\virt_test\site-packages\hypothesis\core.py:563: in execute
result = self.test_runner(data, run)
..\virt_test\site-packages\hypothesis\executors.py:56: in default_new_style_executor
return function(data)
..\virt_test\site-packages\hypothesis\core.py:561: in run
return test(*args, **kwargs)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, content = (u'\n', [0, -1])
@given(content=st_readline(characters=st.characters(blacklist_categories='C')))
def test_tell(space, content):
txt, limits = content
restxt = translate_newlines(txt)
resstr = restxt.encode('utf-8')
for read_chars_before_seeking in range(len(restxt)):
w_stream = W_BytesIO(space)
w_stream.descr_init(space, space.newbytes(txt.encode('utf-8')))
w_textio = W_TextIOWrapper(space)
w_textio.descr_init(
space, w_stream,
encoding='utf-8'
)
w_res1 = w_textio.read_w(space, space.newint(read_chars_before_seeking))
assert space.len_w(w_res1) <= read_chars_before_seeking
w_tell = w_textio.tell_w(space)
w_textio.seek_w(space, space.newint(0)) # seek to beginning
w_textio.seek_w(space, w_tell) # then back to position
w_res2 = w_textio.read_w(space)
w_res = space.add(w_res1, w_res2)
res = space.text_w(w_res)
> assert res == resstr
E assert '\n' == '\r\n'
E -
E + \r
module\_io\test\test_interp_textio.py:170: AssertionError
--------------------------------- Hypothesis ----------------------------------
Falsifying example: test_tell(space=StdObjSpace, content=(u'\n', [0, -1]))
___________________________ test_getstate_setstate ____________________________
space = StdObjSpace
@given(content=st_readline(characters=st.characters(blacklist_categories='C')))
> def test_getstate_setstate(space, content):
module\_io\test\test_interp_textio.py:173:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
..\virt_test\site-packages\hypothesis\core.py:563: in execute
result = self.test_runner(data, run)
..\virt_test\site-packages\hypothesis\executors.py:56: in default_new_style_executor
return function(data)
..\virt_test\site-packages\hypothesis\core.py:561: in run
return test(*args, **kwargs)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, content = (u'\n', [0, -1])
@given(content=st_readline(characters=st.characters(blacklist_categories='C')))
def test_getstate_setstate(space, content):
txt, limits = content
restxt = translate_newlines(txt)
for read_chars_before_getstate in range(len(restxt)):
w_stream = W_BytesIO(space)
w_stream.descr_init(space, space.newbytes(txt.encode('utf-8')))
w_textio = W_TextIOWrapper(space)
w_textio.descr_init(
space, w_stream,
encoding='utf-8'
)
w_state_start = w_textio.w_decoder.getstate_w(space)
w_res1 = w_textio.read_w(space, space.newint(read_chars_before_getstate))
w_current_state = w_textio.w_decoder.getstate_w(space)
w_textio.w_decoder.setstate_w(space, w_state_start)
w_textio.w_decoder.setstate_w(space, w_current_state)
w_res2 = w_textio.read_w(space)
w_res = space.add(w_res1, w_res2)
res = space.text_w(w_res).decode("utf-8")
> assert res == restxt
E assert u'\n' == u'\r\n'
module\_io\test\test_interp_textio.py:194: AssertionError
--------------------------------- Hypothesis ----------------------------------
Falsifying example: test_getstate_setstate(space=StdObjSpace, content=(u'\n', [0, -1]))
=========================== short test summary info ===========================
FAIL module\_io\test\apptest_io.py::test_telling
FAIL module\_io\test\apptest_io.py::test_warn_on_dealloc
FAIL module\_io\test\apptest_io.py::test_tell_univnewlines
FAIL module\_io\test\test_interp_textio.py::test_tell
FAIL module\_io\test\test_interp_textio.py::test_getstate_setstate
============== 5 failed, 286 passed, 9 skipped in 275.45 seconds ==============
++ 05:46:35 starting module/_opcode/test [26 started in total]
__ module/_multibytecodec/test [23 done in total, somefailed=True] ____________
============================= test session starts =============================
platform win32 -- Python 2.7.18[pypy-7.3.18-alpha], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('d:\\pypy_stuff\\buildbot64\\slave\\own-win-x86-64\\build\\pypy\\.hypothesis\\examples')
pytest-2.9.2 from d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pytest.pyc
rootdir: d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build, inifile: pytest.ini
plugins: hypothesis-4.39.3
[platform:msg] Updated environment with vsver 160, using x64 True
[platform:msg] Updated environment with vsver 160, using x64 True
collected 67 items
module\_multibytecodec\test\apptest_codecs.py ...................
module\_multibytecodec\test\apptest_incremental.py ...................F
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
================================== FAILURES ===================================
_________________________ test_incremental_big5hkscs __________________________
def test_incremental_big5hkscs():
import _codecs
import _io
with open(myfile + '/big5hkscs.txt', 'rb') as fid:
uni_str = fid.read()
with open(myfile + '/big5hkscs-utf8.txt', 'rb') as fid:
utf8str = fid.read()
UTF8Reader = _codecs.lookup('utf-8').streamreader
for sizehint in [None] + list(range(1, 33)) + [64, 128, 256, 512, 1024]:
istream = UTF8Reader(_io.BytesIO(utf8str))
ostream = _io.BytesIO()
encoder = IncrementalBig5hkscsEncoder()
while 1:
if sizehint is not None:
data = istream.read(sizehint)
else:
data = istream.read()
if not data:
break
> e = encoder.encode(data)
E (application-level) UnicodeEncodeError: 'big5hkscs' codec can't encode character '\U0002010c' in position 0: illegal multibyte sequence
module\_multibytecodec\test\apptest_incremental.py:270: UnicodeEncodeError
=========================== short test summary info ===========================
FAIL module\_multibytecodec\test\apptest_incremental.py::test_incremental_big5hkscs
============== 1 failed, 64 passed, 2 skipped in 136.17 seconds ===============
++ 05:47:37 starting module/_pickle/test [27 started in total]
__ module/_opcode/test [24 done in total, somefailed=False] ___________________
============================= test session starts =============================
platform win32 -- Python 2.7.18[pypy-7.3.18-alpha], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('d:\\pypy_stuff\\buildbot64\\slave\\own-win-x86-64\\build\\pypy\\.hypothesis\\examples')
pytest-2.9.2 from d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pytest.pyc
rootdir: d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build, inifile: pytest.ini
plugins: hypothesis-4.39.3
[platform:msg] Updated environment with vsver 160, using x64 True
[platform:msg] Updated environment with vsver 160, using x64 True
collected 5 items
module\_opcode\test\apptest_opcode.py .....
========================== 5 passed in 64.51 seconds ==========================
++ 05:47:42 starting module/_pickle_support/test [28 started in total]
__ module/_pickle_support/test [25 done in total, somefailed=False] ___________
============================= test session starts =============================
platform win32 -- Python 2.7.18[pypy-7.3.18-alpha], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('d:\\pypy_stuff\\buildbot64\\slave\\own-win-x86-64\\build\\pypy\\.hypothesis\\examples')
pytest-2.9.2 from d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pytest.pyc
rootdir: d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build, inifile: pytest.ini
plugins: hypothesis-4.39.3
[platform:msg] Updated environment with vsver 160, using x64 True
[platform:msg] Updated environment with vsver 160, using x64 True
collected 1 items
module\_pickle_support\test\apptest__pickle_support.py .
========================== 1 passed in 36.94 seconds ==========================
++ 05:48:21 starting module/_posixsubprocess/test [29 started in total]
__ module/_posixsubprocess/test [26 done in total, somefailed=False] __________
============================= test session starts =============================
platform win32 -- Python 2.7.18[pypy-7.3.18-alpha], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('d:\\pypy_stuff\\buildbot64\\slave\\own-win-x86-64\\build\\pypy\\.hypothesis\\examples')
pytest-2.9.2 from d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pytest.pyc
rootdir: d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 0 items
======================== no tests ran in 0.01 seconds =========================
++ 05:48:22 starting module/_pypyjson/test [30 started in total]
__ module/_multiprocessing/test [27 done in total, somefailed=True] ___________
============================= test session starts =============================
platform win32 -- Python 2.7.18[pypy-7.3.18-alpha], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('d:\\pypy_stuff\\buildbot64\\slave\\own-win-x86-64\\build\\pypy\\.hypothesis\\examples')
pytest-2.9.2 from d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pytest.pyc
rootdir: d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 13 items
module\_multiprocessing\test\test_interp_semaphore.py s
module\_multiprocessing\test\test_semaphore.py s.........E
module\_multiprocessing\test\test_win32.py .
module\_multiprocessing\test\test_ztranslation.py .
=================================== ERRORS ====================================
____________ ERROR at teardown of AppTestSemaphore.test_in_threads ____________
self = <CallInfo when='teardown' exception: {
array [ '%', 'L', 'E', '\x00' ]:
...
File "d:\pypy_stuff\buildbot64\slav...bot64\slave\own-win-x86-64\build\pypy\module\_cffi_backend\ctypefunc.py", line 523, in rawallocate
flavor='raw')
}>
func = <function <lambda> at 0x000001cc809e8368>, when = 'teardown'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=item, **kwds), when=when)
..\_pytest\runner.py:138:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_HookCaller 'pytest_runtest_teardown'>
kwargs = {'__multicall__': <_MultiCall 0 results, 0 meths, kwargs={'item': <AppTestMethod 'test_in_threads'>, 'nextitem': <AppT...s, 0 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_in_threads'>, 'nextitem': <AppTestMethod 'test_closesocket'>}
def __call__(self, **kwargs):
assert not self.is_historic()
> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
..\_pytest\vendored_packages\pluggy.py:724:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.config.PytestPluginManager object at 0x000001ccf4761478>
hook = <_HookCaller 'pytest_runtest_teardown'>, methods = []
kwargs = {'__multicall__': <_MultiCall 0 results, 0 meths, kwargs={'item': <AppTestMethod 'test_in_threads'>, 'nextitem': <AppT...s, 0 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_in_threads'>, 'nextitem': <AppTestMethod 'test_closesocket'>}
def _hookexec(self, hook, methods, kwargs):
# called from all hookcaller instances.
# enable_tracing will set its own wrapping function at self._inner_hookexec
> return self._inner_hookexec(hook, methods, kwargs)
..\_pytest\vendored_packages\pluggy.py:338:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
hook = <_HookCaller 'pytest_runtest_teardown'>, methods = []
kwargs = {'__multicall__': <_MultiCall 0 results, 0 meths, kwargs={'item': <AppTestMethod 'test_in_threads'>, 'nextitem': <AppT...s, 0 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_in_threads'>, 'nextitem': <AppTestMethod 'test_closesocket'>}
self._inner_hookexec = lambda hook, methods, kwargs: \
> _MultiCall(methods, kwargs, hook.spec_opts).execute()
..\_pytest\vendored_packages\pluggy.py:333:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 0 meths, kwargs={'item': <AppTestMethod 'test_in_threads'>, 'nextitem': <AppTestMethod 'test_closesocket'>, '__multicall__': <_MultiCall 0 results, 0 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
> return _wrapped_call(hook_impl.function(*args), self.execute)
..\_pytest\vendored_packages\pluggy.py:595:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
wrap_controller = <generator object pytest_runtest_teardown at 0x000001cc84f4e728>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 0 meths, kwargs={'i...losesocket'>, '__multicall__': <_MultiCall 0 results, 0 meths, kwargs={...}>}>>
def _wrapped_call(wrap_controller, func):
""" Wrap calling to a function with a generator which needs to yield
exactly once. The yield point will trigger calling the wrapped function
and return its _CallOutcome to the yield point. The generator then needs
to finish (raise StopIteration) in order for the wrapped call to complete.
"""
try:
next(wrap_controller) # first yield
except StopIteration:
_raise_wrapfail(wrap_controller, "did not yield")
call_outcome = _CallOutcome(func)
try:
wrap_controller.send(call_outcome)
_raise_wrapfail(wrap_controller, "has second yield")
except StopIteration:
pass
> return call_outcome.get_result()
..\_pytest\vendored_packages\pluggy.py:253:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001cc852aa3e0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001cc852aa3e0>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 0 meths, kwargs={'i...losesocket'>, '__multicall__': <_MultiCall 0 results, 0 meths, kwargs={...}>}>>
def __init__(self, func):
try:
> self.result = func()
..\_pytest\vendored_packages\pluggy.py:264:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 0 meths, kwargs={'item': <AppTestMethod 'test_in_threads'>, 'nextitem': <AppTestMethod 'test_closesocket'>, '__multicall__': <_MultiCall 0 results, 0 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
return _wrapped_call(hook_impl.function(*args), self.execute)
> res = hook_impl.function(*args)
..\_pytest\vendored_packages\pluggy.py:596:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <rpython.conftest.LeakFinder instance at 0x000001ccf6022320>
item = <AppTestMethod 'test_in_threads'>
@pytest.hookimpl(trylast=True)
def pytest_runtest_teardown(self, item):
if not isinstance(item, py.test.collect.Function):
return
if (not getattr(item.obj, 'dont_track_allocations', False)
and leakfinder.TRACK_ALLOCATIONS):
kwds = {}
try:
kwds['do_collection'] = item.track_allocations_collect
except AttributeError:
pass
item._pypytest_leaks = leakfinder.stop_tracking_allocations(False,
**kwds)
else: # stop_tracking_allocations() already called
item._pypytest_leaks = None
# check for leaks, but only if the test passed so far
if getattr(item, '_success', False) and item._pypytest_leaks:
> raise leakfinder.MallocMismatch(item._pypytest_leaks)
E MallocMismatch: {
E
E array [ '%', 'L', 'E', '\x00' ]:
E ...
E File "d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pypy\module\_cffi_backend\cdataobj.py", line 13, in <module>
E from pypy.module._cffi_backend import misc
E File "d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pypy\module\_cffi_backend\misc.py", line 125, in <module>
E FORMAT_LONGDOUBLE = rffi.str2charp("%LE")
E File "d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\rpython\rtyper\lltypesystem\rffi.py", line 829, in str2charp
E array = lltype.malloc(TYPEP.TO, len(s) + 1, flavor='raw', track_allocation=True)
E
E <C object Struct cffi_ctxobj { ctx, info } at 0x1ccf377d400>:
E ...
E File "d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pypy\module\_cffi_backend\ffi_obj.py", line 738, in make_plain_ffi_object
E r.__init__(space, src_ctx)
E File "d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pypy\module\_cffi_backend\ffi_obj.py", line 59, in __init__
E self.ctxobj = parse_c_type.allocate_ctxobj(src_ctx)
E File "d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pypy\module\_cffi_backend\parse_c_type.py", line 71, in allocate_ctxobj
E p = lltype.malloc(CTXOBJ, flavor='raw', zero=True)
E
E <C object Array of Char {'nolength': True} at 0x1ccfb008000>:
E ...
E File "d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pypy\module\_cffi_backend\cdlopen.py", line 131, in ffiobj_init
E ntypes = allocate_array(ffi, _CFFI_OPCODE_T, n)
E File "d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pypy\module\_cffi_backend\cdlopen.py", line 109, in allocate_array
E p = allocate(ffi, nitems * nbytes)
E File "d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pypy\module\_cffi_backend\cdlopen.py", line 102, in allocate
E p = lltype.malloc(rffi.CCHARP.TO, nbytes, flavor='raw', zero=True)
E
E <C object Array of Char {'nolength': True} at 0x1ccfeebd1a0>:
E ...
E File "d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pypy\module\_cffi_backend\ffi_obj.py", line 191, in descr_init
E w__typenames, w__includes)
E File "d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pypy\module\_cffi_backend\cdlopen.py", line 146, in ffiobj_init
E p = allocate(ffi, size)
E File "d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pypy\module\_cffi_backend\cdlopen.py", line 102, in allocate
E p = lltype.malloc(rffi.CCHARP.TO, nbytes, flavor='raw', zero=True)
E
E <C object Array of Char {'nolength': True} at 0x1ccf4ba8ce0>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba8f00>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba8e00>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba8ea0>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba8a40>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba8fa0>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba8d40>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba8c60>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba8e40>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba8ae0>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba8aa0>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba8d00>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba8f40>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba8b00>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba8b40>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba8a00>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba8d80>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba8b20>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba90c0>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba8a60>:
E <C object Array of Char {'nolength': True} at 0x1ccfaa1ceb0>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba9020>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba8f80>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba8b60>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba8ac0>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba8ba0>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba8e20>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba8a80>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba8bc0>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba8c40>:
E <C object Array of Char {'nolength': True} at 0x1ccfdab60b0>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba8f20>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba8be0>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba8f60>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba8cc0>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba9040>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba6980>:
E <C object Array of Char {'nolength': True} at 0x1ccfdab5de0>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba6380>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba63a0>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba6300>:
E <C object Array of Char {'nolength': True} at 0x1ccfdab6440>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba66c0>:
E <C object Array of Char {'nolength': True} at 0x1ccfdab5d80>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba61a0>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba61c0>:
E <C object Array of Char {'nolength': True} at 0x1ccfdab6740>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba6a40>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba6ce0>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba6ba0>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba6b60>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba6b40>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba6be0>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba6d00>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba6b00>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba6c00>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba6d20>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba6f40>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba78a0>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba7740>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba7840>:
E <C object Array of Char {'nolength': True} at 0x1ccfaa1c050>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba7680>:
E <C object Array of Char {'nolength': True} at 0x1ccfaa1d170>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba76a0>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba7700>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba73c0>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba72e0>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba7f20>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba7c60>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba7c20>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba7f60>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba7b80>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba8080>:
E <C object Array of Char {'nolength': True} at 0x1ccfaa1ce40>:
E <C object Array of Char {'nolength': True} at 0x1ccfaa1d430>:
E <C object Array of Char {'nolength': True} at 0x1ccfaa1d8f0>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba7f80>:
E <C object Array of Char {'nolength': True} at 0x1ccfaa1d290>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba8120>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba79c0>:
E <C object Array of Char {'nolength': True} at 0x1ccfaa1d010>:
E <C object Array of Char {'nolength': True} at 0x1ccfaa1d600>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba7ac0>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba7a00>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba7b20>:
E <C object Array of Char {'nolength': True} at 0x1ccfaa1d410>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba8140>:
E <C object Array of Char {'nolength': True} at 0x1ccfaa1d200>:
E <C object Array of Char {'nolength': True} at 0x1ccfaa1d670>:
E ...
E File "d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pypy\module\_cffi_backend\cdlopen.py", line 153, in ffiobj_init
E nglobs[i].c_name = decoder.next_name()
E File "d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pypy\module\_cffi_backend\cdlopen.py", line 92, in next_name
E p = rffi.str2charp(self.string[frm : i])
E File "d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\rpython\rtyper\lltypesystem\rffi.py", line 829, in str2charp
E array = lltype.malloc(TYPEP.TO, len(s) + 1, flavor='raw', track_allocation=True)
E
E <C object Array of Char {'nolength': True} at 0x1ccf84478b0>:
E ...
E File "d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pypy\module\_cffi_backend\cdlopen.py", line 174, in ffiobj_init
E nstructs = allocate_array(ffi, STRUCT_UNION_S, n)
E File "d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pypy\module\_cffi_backend\cdlopen.py", line 109, in allocate_array
E p = allocate(ffi, nitems * nbytes)
E File "d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pypy\module\_cffi_backend\cdlopen.py", line 102, in allocate
E p = lltype.malloc(rffi.CCHARP.TO, nbytes, flavor='raw', zero=True)
E
E <C object Array of Char {'nolength': True} at 0x1ccf6ffed90>:
E ...
E File "d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pypy\module\_cffi_backend\cdlopen.py", line 175, in ffiobj_init
E nfields = allocate_array(ffi, FIELD_S, nftot)
E File "d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pypy\module\_cffi_backend\cdlopen.py", line 109, in allocate_array
E p = allocate(ffi, nitems * nbytes)
E File "d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pypy\module\_cffi_backend\cdlopen.py", line 102, in allocate
E p = lltype.malloc(rffi.CCHARP.TO, nbytes, flavor='raw', zero=True)
E
E <C object Array of Char {'nolength': True} at 0x1ccfba0a3c0>:
E <C object Array of Char {'nolength': True} at 0x1ccf5fe0350>:
E <C object Array of Char {'nolength': True} at 0x1ccf5fe0510>:
E <C object Array of Char {'nolength': True} at 0x1ccf5fe10b0>:
E <C object Array of Char {'nolength': True} at 0x1ccf5fe0280>:
E <C object Array of Char {'nolength': True} at 0x1ccf5fe01b0>:
E <C object Array of Char {'nolength': True} at 0x1ccf5fe0630>:
E <C object Array of Char {'nolength': True} at 0x1ccf5fe0340>:
E <C object Array of Char {'nolength': True} at 0x1ccf5fe11a0>:
E <C object Array of Char {'nolength': True} at 0x1ccf5fe0ce0>:
E <C object Array of Char {'nolength': True} at 0x1ccf5fe1030>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba7de0>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba7ce0>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba7a40>:
E <C object Array of Char {'nolength': True} at 0x1ccf5fe0dd0>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba7b40>:
E <C object Array of Char {'nolength': True} at 0x1ccf5fe0780>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba7d00>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba80a0>:
E <C object Array of Char {'nolength': True} at 0x1ccfdab5db0>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba88c0>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba8880>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba8620>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba8920>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba84a0>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba81a0>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba84c0>:
E <C object Array of Char {'nolength': True} at 0x1ccfdab5ed0>:
E <C object Array of Char {'nolength': True} at 0x1ccf5fe22c0>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba8980>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba87a0>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba8700>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba8fc0>:
E <C object Array of Char {'nolength': True} at 0x1ccf5fe1c30>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba8de0>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba6480>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba71a0>:
E ...
E File "d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pypy\module\_cffi_backend\cdlopen.py", line 185, in ffiobj_init
E nstructs[i].c_name = decoder.next_name()
E File "d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pypy\module\_cffi_backend\cdlopen.py", line 92, in next_name
E p = rffi.str2charp(self.string[frm : i])
E File "d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\rpython\rtyper\lltypesystem\rffi.py", line 829, in str2charp
E array = lltype.malloc(TYPEP.TO, len(s) + 1, flavor='raw', track_allocation=True)
E
E <C object Array of Char {'nolength': True} at 0x1ccf4ba7fe0>:
E <C object Array of Char {'nolength': True} at 0x1ccf5fe0290>:
E <C object Array of Char {'nolength': True} at 0x1ccf5fe0720>:
E <C object Array of Char {'nolength': True} at 0x1ccf5fe0980>:
E <C object Array of Char {'nolength': True} at 0x1ccf5fe0420>:
E <C object Array of Char {'nolength': True} at 0x1ccf5fe07c0>:
E <C object Array of Char {'nolength': True} at 0x1ccf5fe0580>:
E <C object Array of Char {'nolength': True} at 0x1ccf5fe0a40>:
E <C object Array of Char {'nolength': True} at 0x1ccf5fe0750>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba7d80>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba7d60>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba8160>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba7ee0>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba7c00>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba7c80>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba7e60>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba7ba0>:
E <C object Array of Char {'nolength': True} at 0x1ccf5fe0d70>:
E <C object Array of Char {'nolength': True} at 0x1ccf5fe1420>:
E <C object Array of Char {'nolength': True} at 0x1ccf5fe09c0>:
E <C object Array of Char {'nolength': True} at 0x1ccf5fe0f00>:
E <C object Array of Char {'nolength': True} at 0x1ccf5fe04c0>:
E <C object Array of Char {'nolength': True} at 0x1ccf5fe06f0>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba7ca0>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba7da0>:
E <C object Array of Char {'nolength': True} at 0x1ccf5fe15a0>:
E <C object Array of Char {'nolength': True} at 0x1ccf5fe0570>:
E <C object Array of Char {'nolength': True} at 0x1ccf5fe1010>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba7be0>:
E <C object Array of Char {'nolength': True} at 0x1ccf5fe0e10>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba7b00>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba7fc0>:
E <C object Array of Char {'nolength': True} at 0x1ccf5fe18c0>:
E <C object Array of Char {'nolength': True} at 0x1ccf5fe1410>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba7a60>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba7a80>:
E <C object Array of Char {'nolength': True} at 0x1ccf5fe0df0>:
E <C object Array of Char {'nolength': True} at 0x1ccf5fe16c0>:
E <C object Array of Char {'nolength': True} at 0x1ccf5fe1610>:
E <C object Array of Char {'nolength': True} at 0x1ccf5fe0170>:
E <C object Array of Char {'nolength': True} at 0x1ccf5fe1080>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba7fa0>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba7e00>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba7cc0>:
E <C object Array of Char {'nolength': True} at 0x1ccf5fe1630>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba8040>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba8060>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba7d20>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba7ae0>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba7ea0>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba7e20>:
E <C object Array of Char {'nolength': True} at 0x1ccf5fe1b00>:
E <C object Array of Char {'nolength': True} at 0x1ccf5fe0880>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba7e40>:
E <C object Array of Char {'nolength': True} at 0x1ccf5fe16f0>:
E <C object Array of Char {'nolength': True} at 0x1ccf5fe1cd0>:
E <C object Array of Char {'nolength': True} at 0x1ccf5fe20d0>:
E <C object Array of Char {'nolength': True} at 0x1ccf5fe0c40>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba8000>:
E <C object Array of Char {'nolength': True} at 0x1ccf5fe0830>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba7e80>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba80e0>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba8420>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba8300>:
E <C object Array of Char {'nolength': True} at 0x1ccf5fe1760>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba8440>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba82a0>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba8760>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba8540>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba8960>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba8560>:
E <C object Array of Char {'nolength': True} at 0x1ccf5fe10e0>:
E <C object Array of Char {'nolength': True} at 0x1ccf5fe1ce0>:
E <C object Array of Char {'nolength': True} at 0x1ccf5fe21c0>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba81e0>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba8600>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba8580>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba85a0>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba82c0>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba88a0>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba8860>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba8360>:
E <C object Array of Char {'nolength': True} at 0x1ccf5fe0a20>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba8380>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba8460>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba82e0>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba8480>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba8200>:
E <C object Array of Char {'nolength': True} at 0x1ccf5fe2920>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba8820>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba8940>:
E <C object Array of Char {'nolength': True} at 0x1ccf5fe2b10>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba88e0>:
E <C object Array of Char {'nolength': True} at 0x1ccf5fe13c0>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba86c0>:
E <C object Array of Char {'nolength': True} at 0x1ccf5fe1730>:
E <C object Array of Char {'nolength': True} at 0x1ccf5fe29b0>:
E <C object Array of Char {'nolength': True} at 0x1ccf5fe2d60>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba87c0>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba81c0>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba8900>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba86a0>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba83a0>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba8740>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba8840>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba8320>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba83e0>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba8220>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba8260>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba8400>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba8500>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba87e0>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba8240>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba85e0>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba8800>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba8340>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba8660>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba84e0>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba85c0>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba8720>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba8dc0>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba8c20>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba8ca0>:
E <C object Array of Char {'nolength': True} at 0x1ccf5fe3960>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba8c80>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba9060>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba8ec0>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba8d60>:
E <C object Array of Char {'nolength': True} at 0x1ccf5fe35d0>:
E <C object Array of Char {'nolength': True} at 0x1ccf5fe3120>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba9080>:
E <C object Array of Char {'nolength': True} at 0x1ccf5fe1a80>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba6600>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba6660>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba6680>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba6ee0>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba7200>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba72a0>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba7400>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba7420>:
E <C object Array of Char {'nolength': True} at 0x1ccf5fdfda0>:
E ...
E File "d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pypy\module\_cffi_backend\cdlopen.py", line 209, in ffiobj_init
E nfields[nf].c_name = decoder.next_name()
E File "d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pypy\module\_cffi_backend\cdlopen.py", line 92, in next_name
E p = rffi.str2charp(self.string[frm : i])
E File "d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\rpython\rtyper\lltypesystem\rffi.py", line 829, in str2charp
E array = lltype.malloc(TYPEP.TO, len(s) + 1, flavor='raw', track_allocation=True)
E
E <C object Array of Char {'nolength': True} at 0x1ccfa25a780>:
E ...
E File "d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pypy\module\_cffi_backend\cdlopen.py", line 235, in ffiobj_init
E ntypenames = allocate_array(ffi, TYPENAME_S, n)
E File "d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pypy\module\_cffi_backend\cdlopen.py", line 109, in allocate_array
E p = allocate(ffi, nitems * nbytes)
E File "d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pypy\module\_cffi_backend\cdlopen.py", line 102, in allocate
E p = lltype.malloc(rffi.CCHARP.TO, nbytes, flavor='raw', zero=True)
E
E <C object Array of Char {'nolength': True} at 0x1ccf4ba7300>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba8280>:
E <C object Array of Char {'nolength': True} at 0x1ccff1d3780>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba6f60>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba7500>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba80c0>:
E <C object Array of Char {'nolength': True} at 0x1ccf4ba8fe0>:
E <C object Array of Char {'nolength': True} at 0x1ccfc723940>:
E <C object Array of Char {'nolength': True} at 0x1cc803afdf0>:
E <C object Array of Char {'nolength': True} at 0x1ccfc723dd0>:
E <C object Array of Char {'nolength': True} at 0x1cc803afe10>:
E <C object Array of Char {'nolength': True} at 0x1cc803b02d0>:
E <C object Array of Char {'nolength': True} at 0x1cc803afcf0>:
E <C object Array of Char {'nolength': True} at 0x1cc803aff30>:
E <C object Array of Char {'nolength': True} at 0x1cc803b0170>:
E <C object Array of Char {'nolength': True} at 0x1ccfc724010>:
E <C object Array of Char {'nolength': True} at 0x1cc803affb0>:
E <C object Array of Char {'nolength': True} at 0x1ccfdab5c00>:
E <C object Array of Char {'nolength': True} at 0x1cc803b0190>:
E <C object Array of Char {'nolength': True} at 0x1cc803b01b0>:
E <C object Array of Char {'nolength': True} at 0x1ccfc723e90>:
E <C object Array of Char {'nolength': True} at 0x1cc803afd10>:
E <C object Array of Char {'nolength': True} at 0x1cc803afcb0>:
E <C object Array of Char {'nolength': True} at 0x1cc803b0070>:
E <C object Array of Char {'nolength': True} at 0x1cc803afd70>:
E <C object Array of Char {'nolength': True} at 0x1cc803afc50>:
E <C object Array of Char {'nolength': True} at 0x1cc803b0350>:
E <C object Array of Char {'nolength': True} at 0x1cc803afe70>:
E <C object Array of Char {'nolength': True} at 0x1ccfdab6590>:
E <C object Array of Char {'nolength': True} at 0x1cc803afeb0>:
E <C object Array of Char {'nolength': True} at 0x1cc803afed0>:
E <C object Array of Char {'nolength': True} at 0x1ccfdab66b0>:
E <C object Array of Char {'nolength': True} at 0x1cc803affd0>:
E <C object Array of Char {'nolength': True} at 0x1cc803b02f0>:
E <C object Array of Char {'nolength': True} at 0x1cc803afe30>:
E <C object Array of Char {'nolength': True} at 0x1ccfa44b9b0>:
E <C object Array of Char {'nolength': True} at 0x1cc803aff50>:
E <C object Array of Char {'nolength': True} at 0x1cc803b01f0>:
E <C object Array of Char {'nolength': True} at 0x1ccfa44bb50>:
E <C object Array of Char {'nolength': True} at 0x1ccfdab60e0>:
E <C object Array of Char {'nolength': True} at 0x1cc803b0270>:
E <C object Array of Char {'nolength': True} at 0x1cc803b0510>:
E <C object Array of Char {'nolength': True} at 0x1cc803b0b50>:
E <C object Array of Char {'nolength': True} at 0x1cc803b0730>:
E <C object Array of Char {'nolength': True} at 0x1cc803b0890>:
E <C object Array of Char {'nolength': True} at 0x1cc803b0990>:
E <C object Array of Char {'nolength': True} at 0x1cc803b0710>:
E <C object Array of Char {'nolength': True} at 0x1cc803b0bb0>:
E <C object Array of Char {'nolength': True} at 0x1cc803b09b0>:
E <C object Array of Char {'nolength': True} at 0x1ccfa44c320>:
E <C object Array of Char {'nolength': True} at 0x1cc803b0650>:
E <C object Array of Char {'nolength': True} at 0x1cc803b0870>:
E <C object Array of Char {'nolength': True} at 0x1cc803b07d0>:
E <C object Array of Char {'nolength': True} at 0x1cc803b0430>:
E <C object Array of Char {'nolength': True} at 0x1cc803b04f0>:
E <C object Array of Char {'nolength': True} at 0x1cc803b08b0>:
E <C object Array of Char {'nolength': True} at 0x1ccfa44bc10>:
E <C object Array of Char {'nolength': True} at 0x1cc803b0810>:
E <C object Array of Char {'nolength': True} at 0x1cc803b0670>:
E <C object Array of Char {'nolength': True} at 0x1cc803b0b70>:
E <C object Array of Char {'nolength': True} at 0x1cc803b0930>:
E <C object Array of Char {'nolength': True} at 0x1ccfdab5c30>:
E <C object Array of Char {'nolength': True} at 0x1ccfa4486a0>:
E <C object Array of Char {'nolength': True} at 0x1cc803b09d0>:
E <C object Array of Char {'nolength': True} at 0x1cc803b05b0>:
E <C object Array of Char {'nolength': True} at 0x1ccfa44ba80>:
E ...
E File "d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pypy\module\_cffi_backend\cdlopen.py", line 239, in ffiobj_init
E ntypenames[i].c_name = decoder.next_name()
E File "d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pypy\module\_cffi_backend\cdlopen.py", line 92, in next_name
E p = rffi.str2charp(self.string[frm : i])
E File "d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\rpython\rtyper\lltypesystem\rffi.py", line 829, in str2charp
E array = lltype.malloc(TYPEP.TO, len(s) + 1, flavor='raw', track_allocation=True)
E
E <C object Struct CIF_DESCRIPTION { cif, abi, nargs, rtype, atypes, exchange_size, exchange_result, exchange_args } at 0x1ccff5e1590>:
E ...
E File "d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pypy\module\_cffi_backend\newtype.py", line 752, in _build_function_type
E fct = ctypefunc.W_CTypeFunc(space, fargs, fresult, ellipsis, abi)
E File "d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pypy\module\_cffi_backend\ctypefunc.py", line 53, in __init__
E builder.rawallocate(self)
E File "d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pypy\module\_cffi_backend\ctypefunc.py", line 523, in rawallocate
E flavor='raw')
E }
..\rpython\conftest.py:103: MallocMismatch
=============== 11 passed, 2 skipped, 1 error in 217.68 seconds ===============
++ 05:49:56 starting module/_random/test [31 started in total]
__ module/_pickle/test [28 done in total, somefailed=False] ___________________
============================= test session starts =============================
platform win32 -- Python 2.7.18[pypy-7.3.18-alpha], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('d:\\pypy_stuff\\buildbot64\\slave\\own-win-x86-64\\build\\pypy\\.hypothesis\\examples')
pytest-2.9.2 from d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pytest.pyc
rootdir: d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build, inifile: pytest.ini
plugins: hypothesis-4.39.3
[platform:msg] Updated environment with vsver 160, using x64 True
[platform:msg] Updated environment with vsver 160, using x64 True
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 156.45 seconds ===================
++ 05:50:19 starting module/_rawffi/alt/test [32 started in total]
__ module/_pypyjson/test [29 done in total, somefailed=False] _________________
============================= test session starts =============================
platform win32 -- Python 2.7.18[pypy-7.3.18-alpha], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('d:\\pypy_stuff\\buildbot64\\slave\\own-win-x86-64\\build\\pypy\\.hypothesis\\examples')
pytest-2.9.2 from d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pytest.pyc
rootdir: d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build, inifile: pytest.ini
plugins: hypothesis-4.39.3
[platform:msg] Updated environment with vsver 160, using x64 True
[platform:msg] Updated environment with vsver 160, using x64 True
collected 57 items
module\_pypyjson\test\apptest__pypyjson.py ..........
module\_pypyjson\test\test__pypyjson.py ............................................
module\_pypyjson\test\test_simd.py ...
========================= 57 passed in 147.13 seconds =========================
++ 05:50:57 starting module/_rawffi/test [33 started in total]
__ module/_random/test [30 done in total, somefailed=False] ___________________
============================= test session starts =============================
platform win32 -- Python 2.7.18[pypy-7.3.18-alpha], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('d:\\pypy_stuff\\buildbot64\\slave\\own-win-x86-64\\build\\pypy\\.hypothesis\\examples')
pytest-2.9.2 from d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pytest.pyc
rootdir: d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 13 items
module\_random\test\test_random.py ............
module\_random\test\test_ztranslation.py .
========================= 13 passed in 65.39 seconds ==========================
++ 05:51:03 starting module/_socket/test [34 started in total]
__ module/_rawffi/alt/test [31 done in total, somefailed=False] _______________
============================= test session starts =============================
platform win32 -- Python 2.7.18[pypy-7.3.18-alpha], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('d:\\pypy_stuff\\buildbot64\\slave\\own-win-x86-64\\build\\pypy\\.hypothesis\\examples')
pytest-2.9.2 from d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pytest.pyc
rootdir: d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 73 items
module\_rawffi\alt\test\test_ffitype.py .....
module\_rawffi\alt\test\test_funcptr.py ..s..............................ss.ss....
module\_rawffi\alt\test\test_struct.py ...............
module\_rawffi\alt\test\test_type_converter.py ...........
==================== 68 passed, 5 skipped in 68.91 seconds ====================
++ 05:51:33 starting module/_sre/test [35 started in total]
__ module/_rawffi/test [32 done in total, somefailed=True] ____________________
============================= test session starts =============================
platform win32 -- Python 2.7.18[pypy-7.3.18-alpha], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('d:\\pypy_stuff\\buildbot64\\slave\\own-win-x86-64\\build\\pypy\\.hypothesis\\examples')
pytest-2.9.2 from d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pytest.pyc
rootdir: d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build, inifile: pytest.ini
plugins: hypothesis-4.39.3
[platform:msg] Updated environment with vsver 160, using x64 True
[platform:msg] Updated environment with vsver 160, using x64 True
collected 86 items
module\_rawffi\test\apptest_rawffi.py ..
module\_rawffi\test\test__rawffi.py ..F...............s.................................s.................
module\_rawffi\test\test_exit.py s
module\_rawffi\test\test_nested.py ......
module\_rawffi\test\test_struct.py ...
module\_rawffi\test\test_tracker.py ...
module\_rawffi\test\test_ztranslation.py .
================================== FAILURES ===================================
__________________ AppTestFfi.test_libload_fail_nonutf8_name __________________
self = <CallInfo when='call' exception: unichr() arg out of range>
func = <function <lambda> at 0x00000264c4b84188>, when = 'call'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=item, **kwds), when=when)
..\_pytest\runner.py:138:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_HookCaller 'pytest_runtest_call'>
kwargs = {'__multicall__': <_MultiCall 0 results, 1 meths, kwargs={'item': <AppTestMethod 'test_libload_fail_nonutf8_name'>, '__multicall__': <_MultiCall 0 results, 1 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_libload_fail_nonutf8_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 0x00000264bb323408>
hook = <_HookCaller 'pytest_runtest_call'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000264bcbe7a60>]
kwargs = {'__multicall__': <_MultiCall 0 results, 1 meths, kwargs={'item': <AppTestMethod 'test_libload_fail_nonutf8_name'>, '__multicall__': <_MultiCall 0 results, 1 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_libload_fail_nonutf8_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_call'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000264bcbe7a60>]
kwargs = {'__multicall__': <_MultiCall 0 results, 1 meths, kwargs={'item': <AppTestMethod 'test_libload_fail_nonutf8_name'>, '__multicall__': <_MultiCall 0 results, 1 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_libload_fail_nonutf8_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, 1 meths, kwargs={'item': <AppTestMethod 'test_libload_fail_nonutf8_name'>, '__multicall__': <_MultiCall 0 results, 1 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
> return _wrapped_call(hook_impl.function(*args), self.execute)
..\_pytest\vendored_packages\pluggy.py:595:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
wrap_controller = <generator object pytest_runtest_call at 0x00000264c4be5e20>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 1 meths, kwargs={'i...nutf8_name'>, '__multicall__': <_MultiCall 0 results, 1 meths, kwargs={...}>}>>
def _wrapped_call(wrap_controller, func):
""" Wrap calling to a function with a generator which needs to yield
exactly once. The yield point will trigger calling the wrapped function
and return its _CallOutcome to the yield point. The generator then needs
to finish (raise StopIteration) in order for the wrapped call to complete.
"""
try:
next(wrap_controller) # first yield
except StopIteration:
_raise_wrapfail(wrap_controller, "did not yield")
call_outcome = _CallOutcome(func)
try:
wrap_controller.send(call_outcome)
_raise_wrapfail(wrap_controller, "has second yield")
except StopIteration:
pass
> return call_outcome.get_result()
..\_pytest\vendored_packages\pluggy.py:253:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000264c4c26720>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000264c4c26720>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 1 meths, kwargs={'i...nutf8_name'>, '__multicall__': <_MultiCall 0 results, 1 meths, kwargs={...}>}>>
def __init__(self, func):
try:
> self.result = func()
..\_pytest\vendored_packages\pluggy.py:264:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 1 meths, kwargs={'item': <AppTestMethod 'test_libload_fail_nonutf8_name'>, '__multicall__': <_MultiCall 0 results, 1 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
> return _wrapped_call(hook_impl.function(*args), self.execute)
..\_pytest\vendored_packages\pluggy.py:595:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
wrap_controller = <generator object pytest_runtest_call at 0x00000264c4be5d58>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 1 meths, kwargs={'i...nutf8_name'>, '__multicall__': <_MultiCall 0 results, 1 meths, kwargs={...}>}>>
def _wrapped_call(wrap_controller, func):
""" Wrap calling to a function with a generator which needs to yield
exactly once. The yield point will trigger calling the wrapped function
and return its _CallOutcome to the yield point. The generator then needs
to finish (raise StopIteration) in order for the wrapped call to complete.
"""
try:
next(wrap_controller) # first yield
except StopIteration:
_raise_wrapfail(wrap_controller, "did not yield")
call_outcome = _CallOutcome(func)
try:
wrap_controller.send(call_outcome)
_raise_wrapfail(wrap_controller, "has second yield")
except StopIteration:
pass
> return call_outcome.get_result()
..\_pytest\vendored_packages\pluggy.py:253:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000264c4c266e0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000264c4c266e0>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 1 meths, kwargs={'i...nutf8_name'>, '__multicall__': <_MultiCall 0 results, 1 meths, kwargs={...}>}>>
def __init__(self, func):
try:
> self.result = func()
..\_pytest\vendored_packages\pluggy.py:264:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 1 meths, kwargs={'item': <AppTestMethod 'test_libload_fail_nonutf8_name'>, '__multicall__': <_MultiCall 0 results, 1 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
return _wrapped_call(hook_impl.function(*args), self.execute)
> res = hook_impl.function(*args)
..\_pytest\vendored_packages\pluggy.py:596:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
item = <AppTestMethod 'test_libload_fail_nonutf8_name'>
def pytest_runtest_call(item):
try:
> item.runtest()
..\_pytest\runner.py:91:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <AppTestMethod 'test_libload_fail_nonutf8_name'>
def runtest(self):
target = self.obj
src = extract_docstring_if_empty_function(target.im_func)
space = target.im_self.space
if self.config.option.runappdirect:
appexec_definitions = self.parent.obj.__dict__
spaceconfig = getattr(self.parent.obj, 'spaceconfig', None)
usemodules = spaceconfig.get('usemodules') if spaceconfig else None
return run_with_python(self.config.option.python, src, usemodules,
**appexec_definitions)
filename = self._getdynfilename(target)
func = app2interp_temp(src, filename=filename)
w_instance = self.parent.w_instance
> self.execute_appex(space, func, space, w_instance)
tool\pytest\apptest.py:345:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <AppTestMethod 'test_libload_fail_nonutf8_name'>, space = StdObjSpace
target = <function test_libload_fail_nonutf8_name at 0x00000264c4b842f0>
args = (StdObjSpace, <pypy.interpreter.typedef.W_ObjectObjectUserDictWeakrefable object at 0x00000264c1457ef8>)
def execute_appex(self, space, target, *args):
self.space = space
space.getexecutioncontext().set_sys_exc_info(None)
try:
> target(*args)
tool\pytest\apptest.py:281:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
args_w = (<pypy.interpreter.typedef.W_ObjectObjectUserDictWeakrefable object at 0x00000264c1457ef8>,)
w_func = <Function test_libload_fail_nonutf8_name>
args = <pypy.interpreter.typedef.W_ObjectObjectUserDictWeakrefable object at 0x00000264c1457ef8>
def appcaller(space, *args_w):
if not isinstance(space, ObjSpace):
raise TypeError("first argument must be a space instance.")
# the last argument can be an Arguments
w_func = self.wget(space, name)
if not args_w:
return space.call_function(w_func)
else:
args = args_w[-1]
assert args is not None
if not isinstance(args, Arguments):
> return space.call_function(w_func, *args_w)
interpreter\gateway.py:1409:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace, w_func = <Function test_libload_fail_nonutf8_name>
args_w = (<pypy.interpreter.typedef.W_ObjectObjectUserDictWeakrefable object at 0x00000264c1457ef8>,)
nargs = 1, Function = <class 'pypy.interpreter.function.Function'>
_Method = <class 'pypy.interpreter.function._Method'>
def call_function(self, w_func, *args_w):
nargs = len(args_w) # used for pruning funccall versions
if not self.config.objspace.disable_call_speedhacks and nargs < 5:
# start of hack for performance
from pypy.interpreter.function import Function, _Method
if isinstance(w_func, _Method):
if nargs < 4:
func = w_func.w_function
if isinstance(func, Function):
return func.funccall(w_func.w_instance, *args_w)
if isinstance(w_func, Function):
> return w_func.funccall(*args_w)
interpreter\baseobjspace.py:1260:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Function test_libload_fail_nonutf8_name>
args_w = (<pypy.interpreter.typedef.W_ObjectObjectUserDictWeakrefable object at 0x00000264c1457ef8>,)
gateway = <module 'pypy.interpreter.gateway' from 'd:\\pypy_stuff\\buildbot64\\slave\\own-win-x86-64\\build\\pypy\\interpreter\\gateway.pyc'>
PyCode = <class 'pypy.interpreter.pycode.PyCode'>
code = <code object test_libload_fail_nonutf8_name, file "[d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pypy\module\_rawffi\test\test__rawffi.py:283]", line 1>
def funccall(self, *args_w): # speed hack
from pypy.interpreter import gateway
from pypy.interpreter.pycode import PyCode
code = self.getcode() # hook for the jit
nargs = len(args_w)
fast_natural_arity = code.fast_natural_arity
if nargs == fast_natural_arity:
if nargs == 0:
assert isinstance(code, gateway.BuiltinCode0)
return code.fastcall_0(self.space, self)
elif nargs == 1:
assert isinstance(code, gateway.BuiltinCode1)
return code.fastcall_1(self.space, self, args_w[0])
elif nargs == 2:
assert isinstance(code, gateway.BuiltinCode2)
return code.fastcall_2(self.space, self, args_w[0], args_w[1])
elif nargs == 3:
assert isinstance(code, gateway.BuiltinCode3)
return code.fastcall_3(self.space, self, args_w[0],
args_w[1], args_w[2])
elif nargs == 4:
assert isinstance(code, gateway.BuiltinCode4)
return code.fastcall_4(self.space, self, args_w[0],
args_w[1], args_w[2], args_w[3])
elif (nargs | PyCode.FLATPYCALL) == fast_natural_arity:
assert isinstance(code, PyCode)
if nargs < 5:
new_frame = self.space.createframe(code, self.w_func_globals,
self)
for i in funccallunrolling:
if i < nargs:
new_frame.locals_cells_stack_w[i] = args_w[i]
> return new_frame.run(self.name, self.qualname)
interpreter\function.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.objspace.std.frame.StdObjSpaceFrame executing <code object test_libload_...-x86-64\build\pypy\module\_rawffi\test\test__rawffi.py:283]", line 1> at line 6
name = 'test_libload_fail_nonutf8_name'
qualname = 'test_libload_fail_nonutf8_name'
def run(self, name=None, qualname=None):
"""Start this frame's execution."""
if self._is_generator_or_coroutine():
return self.initialize_as_generator(name, qualname)
else:
> return self.execute_frame(None)
interpreter\pyframe.py:265:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.objspace.std.frame.StdObjSpaceFrame executing <code object test_libload_...-x86-64\build\pypy\module\_rawffi\test\test__rawffi.py:283]", line 1> at line 6
w_arg_or_err = None
def execute_frame(self, w_arg_or_err=None):
"""Execute this frame. Main entry point to the interpreter.
'w_arg_or_err' is non-None iff we are starting or resuming
a generator or coroutine frame; in that case, w_arg_or_err
is the input argument -or- an SApplicationException instance.
"""
from pypy.interpreter import pyopcode as pyopcode
# the following 'assert' is an annotation hint: it hides from
# the annotator all methods that are defined in PyFrame but
# overridden in the {,Host}FrameClass subclasses of PyFrame.
assert (isinstance(self, self.space.FrameClass) or
not self.space.config.translating)
executioncontext = self.space.getexecutioncontext()
executioncontext.enter(self)
got_exception = True
w_exitvalue = self.space.w_None
try:
executioncontext.call_trace(self)
if should_fire_local_any(self.space, self.getcode(), FRAME_ENTRY_EVENTS):
self._monitor_frame_entry(w_arg_or_err)
#
# Execution starts just after the last_instr. Initially,
# last_instr is -1. After a generator suspends it points to
# the YIELD_VALUE/YIELD_FROM instruction.
try:
try:
if w_arg_or_err is None:
assert self.last_instr == -1
next_instr = r_uint(0)
else:
next_instr = self.resume_execute_frame(w_arg_or_err)
except pyopcode.Yield:
w_exitvalue = self.popvalue()
else:
w_exitvalue = self.dispatch(self.pycode, next_instr,
executioncontext)
except OperationError:
raise
except Exception as e: # general fall-back
> raise self._convert_unexpected_exception(e)
interpreter\pyframe.py:399:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.objspace.std.frame.StdObjSpaceFrame executing <code object test_libload_...-x86-64\build\pypy\module\_rawffi\test\test__rawffi.py:283]", line 1> at line 6
e = ValueError('unichr() arg out of range',)
def _convert_unexpected_exception(self, e):
from pypy.interpreter import error
> operr = error.get_converted_unexpected_exception(self.space, e)
interpreter\pyframe.py:890:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.objspace.std.frame.StdObjSpaceFrame executing <code object test_libload_...-x86-64\build\pypy\module\_rawffi\test\test__rawffi.py:283]", line 1> at line 6
w_arg_or_err = None
def execute_frame(self, w_arg_or_err=None):
"""Execute this frame. Main entry point to the interpreter.
'w_arg_or_err' is non-None iff we are starting or resuming
a generator or coroutine frame; in that case, w_arg_or_err
is the input argument -or- an SApplicationException instance.
"""
from pypy.interpreter import pyopcode as pyopcode
# the following 'assert' is an annotation hint: it hides from
# the annotator all methods that are defined in PyFrame but
# overridden in the {,Host}FrameClass subclasses of PyFrame.
assert (isinstance(self, self.space.FrameClass) or
not self.space.config.translating)
executioncontext = self.space.getexecutioncontext()
executioncontext.enter(self)
got_exception = True
w_exitvalue = self.space.w_None
try:
executioncontext.call_trace(self)
if should_fire_local_any(self.space, self.getcode(), FRAME_ENTRY_EVENTS):
self._monitor_frame_entry(w_arg_or_err)
#
# Execution starts just after the last_instr. Initially,
# last_instr is -1. After a generator suspends it points to
# the YIELD_VALUE/YIELD_FROM instruction.
try:
try:
if w_arg_or_err is None:
assert self.last_instr == -1
next_instr = r_uint(0)
else:
next_instr = self.resume_execute_frame(w_arg_or_err)
except pyopcode.Yield:
w_exitvalue = self.popvalue()
else:
w_exitvalue = self.dispatch(self.pycode, next_instr,
> executioncontext)
interpreter\pyframe.py:395:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.objspace.std.frame.StdObjSpaceFrame executing <code object test_libload_...-x86-64\build\pypy\module\_rawffi\test\test__rawffi.py:283]", line 1> at line 6
pycode = <code object test_libload_fail_nonutf8_name, file "[d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pypy\module\_rawffi\test\test__rawffi.py:283]", line 1>
next_instr = 0L
ec = <pypy.interpreter.executioncontext.ExecutionContext object at 0x00000264c3b4f210>
def dispatch(self, pycode, next_instr, ec):
# For the sequel, force 'next_instr' to be unsigned for performance
next_instr = r_uint(next_instr)
co_code = pycode.co_code
try:
while True:
assert next_instr & 1 == 0
> next_instr = self.handle_bytecode(co_code, next_instr, ec)
interpreter\pyopcode.py:73:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.objspace.std.frame.StdObjSpaceFrame executing <code object test_libload_...-x86-64\build\pypy\module\_rawffi\test\test__rawffi.py:283]", line 1> at line 6
co_code = 'd\x01d\x00l\x00}\x01d\x01d\x00l\x01}\x02\t\x00|\x01\xa0\x02d\x02\xa1\x01\x01\x00t\x03d\x03\x83\x01\x82\x01#\x00t\x04$...\x01Y\x00d\x00}\x03~\x03y\x00d\x00}\x03~\x03w\x01w\x00&\x03Y\x00w\x01\x03y\x00d\x00}\x03~\x03w\x01w\x00&\x03Y\x00w\x01'
next_instr = 0L
ec = <pypy.interpreter.executioncontext.ExecutionContext object at 0x00000264c3b4f210>
def handle_bytecode(self, co_code, next_instr, ec):
try:
> next_instr = self.dispatch_bytecode(co_code, next_instr, ec)
interpreter\pyopcode.py:79:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.objspace.std.frame.StdObjSpaceFrame executing <code object test_libload_...-x86-64\build\pypy\module\_rawffi\test\test__rawffi.py:283]", line 1> at line 6
co_code = 'd\x01d\x00l\x00}\x01d\x01d\x00l\x01}\x02\t\x00|\x01\xa0\x02d\x02\xa1\x01\x01\x00t\x03d\x03\x83\x01\x82\x01#\x00t\x04$...\x01Y\x00d\x00}\x03~\x03y\x00d\x00}\x03~\x03w\x01w\x00&\x03Y\x00w\x01\x03y\x00d\x00}\x03~\x03w\x01w\x00&\x03Y\x00w\x01'
next_instr = 26L
ec = <pypy.interpreter.executioncontext.ExecutionContext object at 0x00000264c3b4f210>
@jit.unroll_safe
def dispatch_bytecode(self, co_code, next_instr, ec):
while True:
assert next_instr & 1 == 0
self.last_instr = intmask(next_instr)
pycode = self.getcode()
if should_fire_local_any(ec.space, pycode, LOCAL_LINE_INSTRUCTION_MASK):
self._monitor_line_and_instruction(pycode)
if jit.we_are_jitted():
_d = self.debugdata
if ec.space.reverse_debugging or (
_d is not None and _d.w_f_trace is not None):
ec.bytecode_only_trace(self)
next_instr = r_uint(self.last_instr)
else:
# Only reload next_instr from last_instr when something that
# can modify it actually ran (trace function or action
# dispatcher). In the common case (no trace, positive ticker)
# next_instr is unchanged and the round-trip is skipped.
_d = self.debugdata
if ec.space.reverse_debugging or (
_d is not None and _d.w_f_trace is not None) or (
not we_are_translated() and
'bytecode_only_trace' in ec.__dict__):
ec.bytecode_only_trace(self)
next_instr = r_uint(self.last_instr)
actionflag = ec.space.actionflag
if actionflag.decrement_ticker(TICK_COUNTER_STEP) < 0:
actionflag.action_dispatcher(ec, self)
next_instr = r_uint(self.last_instr)
opcode = ord(co_code[next_instr])
oparg = ord(co_code[next_instr + 1])
next_instr += 2
# note: the structure of the code here is such that it makes
# (after translation) a big "if/elif" chain, which is then
# turned into computed gotos.
while opcode == opcodedesc.EXTENDED_ARG.index:
opcode = ord(co_code[next_instr])
arg = ord(co_code[next_instr + 1])
if opcode < HAVE_ARGUMENT:
raise BytecodeCorruption
next_instr += 2
oparg = (oparg * 256) | arg
if opcode == opcodedesc.RETURN_VALUE.index:
if should_fire_local(ec.space, pycode, PY_RETURN):
dispatch_code_event(
ec.space, PY_RETURN, pycode, intmask(self.last_instr),
self.peekvalue())
self.frame_finished_execution = True # for generators
raise Return
elif opcode == opcodedesc.RETURN_CONST.index:
self.pushvalue(self.getconstant_w(oparg))
self.frame_finished_execution = True # for generators
raise Return
elif opcode == opcodedesc.JUMP_ABSOLUTE.index:
dest = self.jump_absolute(oparg, next_instr, ec)
self._monitor_branch(JUMP, dest)
return dest
elif opcode == opcodedesc.RERAISE.index:
return self.RERAISE(oparg, next_instr)
elif opcode == opcodedesc.FOR_ITER.index:
next_instr = self.FOR_ITER(oparg, next_instr)
elif opcode == opcodedesc.JUMP_FORWARD.index:
next_instr = self.JUMP_FORWARD(oparg, next_instr)
elif opcode == opcodedesc.JUMP_IF_FALSE_OR_POP.index:
return self.JUMP_IF_FALSE_OR_POP(oparg, next_instr, ec)
elif opcode == opcodedesc.JUMP_IF_TRUE_OR_POP.index:
return self.JUMP_IF_TRUE_OR_POP(oparg, next_instr, ec)
elif opcode == opcodedesc.POP_JUMP_IF_FALSE.index:
return self.POP_JUMP_IF_FALSE(oparg, next_instr, ec)
elif opcode == opcodedesc.POP_JUMP_IF_TRUE.index:
return self.POP_JUMP_IF_TRUE(oparg, next_instr, ec)
elif opcode == opcodedesc.POP_JUMP_FORWARD_IF_NONE.index:
next_instr = self.POP_JUMP_FORWARD_IF_NONE(oparg, next_instr)
elif opcode == opcodedesc.POP_JUMP_FORWARD_IF_NOT_NONE.index:
next_instr = self.POP_JUMP_FORWARD_IF_NOT_NONE(oparg, next_instr)
elif opcode == opcodedesc.JUMP_IF_NOT_EXC_MATCH.index:
next_instr = self.JUMP_IF_NOT_EXC_MATCH(oparg, next_instr)
elif opcode == opcodedesc.BINARY_ADD.index:
self.BINARY_ADD(oparg, next_instr)
elif opcode == opcodedesc.BINARY_AND.index:
self.BINARY_AND(oparg, next_instr)
elif opcode == opcodedesc.BINARY_FLOOR_DIVIDE.index:
self.BINARY_FLOOR_DIVIDE(oparg, next_instr)
elif opcode == opcodedesc.BINARY_MATRIX_MULTIPLY.index:
self.BINARY_MATRIX_MULTIPLY(oparg, next_instr)
elif opcode == opcodedesc.BINARY_LSHIFT.index:
self.BINARY_LSHIFT(oparg, next_instr)
elif opcode == opcodedesc.BINARY_MODULO.index:
self.BINARY_MODULO(oparg, next_instr)
elif opcode == opcodedesc.BINARY_MULTIPLY.index:
self.BINARY_MULTIPLY(oparg, next_instr)
elif opcode == opcodedesc.BINARY_OR.index:
self.BINARY_OR(oparg, next_instr)
elif opcode == opcodedesc.BINARY_POWER.index:
self.BINARY_POWER(oparg, next_instr)
elif opcode == opcodedesc.BINARY_RSHIFT.index:
self.BINARY_RSHIFT(oparg, next_instr)
elif opcode == opcodedesc.BINARY_SUBSCR.index:
self.BINARY_SUBSCR(oparg, next_instr)
elif opcode == opcodedesc.BINARY_SUBTRACT.index:
self.BINARY_SUBTRACT(oparg, next_instr)
elif opcode == opcodedesc.BINARY_TRUE_DIVIDE.index:
self.BINARY_TRUE_DIVIDE(oparg, next_instr)
elif opcode == opcodedesc.BINARY_XOR.index:
self.BINARY_XOR(oparg, next_instr)
elif opcode == opcodedesc.BUILD_CONST_KEY_MAP.index:
self.BUILD_CONST_KEY_MAP(oparg, next_instr)
elif opcode == opcodedesc.BUILD_LIST.index:
self.BUILD_LIST(oparg, next_instr)
elif opcode == opcodedesc.BUILD_LIST_FROM_ARG.index:
self.BUILD_LIST_FROM_ARG(oparg, next_instr)
elif opcode == opcodedesc.BUILD_MAP.index:
self.BUILD_MAP(oparg, next_instr)
elif opcode == opcodedesc.BUILD_SET.index:
self.BUILD_SET(oparg, next_instr)
elif opcode == opcodedesc.BUILD_SLICE.index:
self.BUILD_SLICE(oparg, next_instr)
elif opcode == opcodedesc.BUILD_TUPLE.index:
self.BUILD_TUPLE(oparg, next_instr)
elif opcode == opcodedesc.CALL_FUNCTION.index:
self.CALL_FUNCTION(oparg, next_instr)
elif opcode == opcodedesc.CALL_FUNCTION_KW.index:
self.CALL_FUNCTION_KW(oparg, next_instr)
elif opcode == opcodedesc.CALL_FUNCTION_EX.index:
self.CALL_FUNCTION_EX(oparg, next_instr)
elif opcode == opcodedesc.CALL_METHOD.index:
> self.CALL_METHOD(oparg, next_instr)
interpreter\pyopcode.py:370:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
f = <pypy.objspace.std.frame.StdObjSpaceFrame executing <code object test_libload_...-x86-64\build\pypy\module\_rawffi\test\test__rawffi.py:283]", line 1> at line 6
oparg = 1, ignored = (26L,), n_args = 1, w_self = None, n = 1
@jit.unroll_safe
def CALL_METHOD(f, oparg, *ignored):
# opargs contains the arg, and kwarg count, excluding the implicit 'self'
n_args = oparg
w_self = f.peekvalue_maybe_none(n_args)
n = n_args + (w_self is not None)
w_callable = f.peekvalue(n_args + 1)
w_result = f.space.call_valuestack(
> w_callable, n, f, methodcall=w_self is not None, dropvalues=n_args+2)
objspace\std\callmethod.py:93:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace, w_func = <W_TypeObject 'CDLL' at 0x264c15ddde0>, nargs = 1
frame = <pypy.objspace.std.frame.StdObjSpaceFrame executing <code object test_libload_...-x86-64\build\pypy\module\_rawffi\test\test__rawffi.py:283]", line 1> at line 6
dropvalues = 3, methodcall = False
def call_valuestack(self, w_func, nargs, frame, dropvalues, methodcall=False):
# methodcall is only used for better error messages in argument.py
from pypy.interpreter.function import (
Function, _Method, is_builtin_code, is_python_function)
from pypy.interpreter.pymonitoring import (
should_fire_local, dispatch_code_event, w_missing, CALL)
pycode = frame.getcode()
call_wants_events = should_fire_local(self, pycode, CALL)
if call_wants_events:
w_arg0 = frame.peekvalue(nargs - 1) if nargs > 0 else w_missing(self)
dispatch_code_event(
self, CALL, pycode, frame.last_instr, w_func, w_arg0)
needs_c_wrap = (
(frame.get_is_being_profiled() and is_builtin_code(w_func)) or
(call_wants_events and not is_python_function(w_func)))
if needs_c_wrap:
# XXX: this code is copied&pasted :-( from the slow path below
# call_valuestack().
args = frame.make_arguments(nargs, w_function=w_func)
frame.dropvalues(dropvalues)
return self.call_args_and_c_profile(frame, w_func, args)
if not self.config.objspace.disable_call_speedhacks:
# start of hack for performance
if isinstance(w_func, _Method):
# reuse callable stack place for w_inst
frame.settopvalue(w_func.w_instance, nargs)
nargs += 1
methodcall = True
w_func = w_func.w_function
if isinstance(w_func, Function):
return w_func.funccall_valuestack(
nargs, frame, methodcall=methodcall, dropvalues=dropvalues)
# end of hack for performance
args = frame.make_arguments(nargs, w_function=w_func)
frame.dropvalues(dropvalues)
> return self.call_args(w_func, args)
interpreter\baseobjspace.py:1306:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'CDLL' at 0x264c15ddde0>
args = Arguments([W_BytesObject('missing\xff.so')])
def call_args(space, w_obj, args):
# two special cases for performance
if isinstance(w_obj, Function):
return w_obj.call_args(args)
if isinstance(w_obj, Method):
return w_obj.call_args(args)
w_descr = space.lookup(w_obj, '__call__')
if w_descr is None:
raise oefmt(space.w_TypeError,
"'%T' object is not callable", w_obj)
> return space.get_and_call_args(w_descr, w_obj, args)
objspace\descroperation.py:208:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_descr = <FunctionWithFixedCode __call__>
w_obj = <W_TypeObject 'CDLL' at 0x264c15ddde0>
args = Arguments([W_BytesObject('missing\xff.so')])
def get_and_call_args(space, w_descr, w_obj, args):
# a special case for performance and to avoid infinite recursion
if isinstance(w_descr, Function):
> return w_descr.call_obj_args(w_obj, args)
objspace\descroperation.py:173:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <FunctionWithFixedCode __call__>
w_obj = <W_TypeObject 'CDLL' at 0x264c15ddde0>
args = Arguments([W_BytesObject('missing\xff.so')])
def call_obj_args(self, w_obj, args):
# delegate activation to code
> w_res = self.getcode().funcrun_obj(self, w_obj, args)
interpreter\function.py:88:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.interpreter.gateway.BuiltinCodePassThroughArguments1 object at 0x00000264c0c80d40>
func = <FunctionWithFixedCode __call__>
w_obj = <W_TypeObject 'CDLL' at 0x264c15ddde0>
args = Arguments([W_BytesObject('missing\xff.so')])
def funcrun_obj(self, func, w_obj, args):
space = func.space
try:
w_result = self.func__args__(space, w_obj, args)
except DescrMismatch:
return self._type_unwrap_mismatch(space, args.prepend(w_obj))
except Exception as e:
> self.handle_exception(space, e)
interpreter\gateway.py:941:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.interpreter.gateway.BuiltinCodePassThroughArguments1 object at 0x00000264c0c80d40>
space = StdObjSpace, e = ValueError('unichr() arg out of range',)
def handle_exception(self, space, e):
try:
if not we_are_translated():
raise
raise e
except OperationError:
raise
except Exception as e: # general fall-back
from pypy.interpreter import error
> raise error.get_converted_unexpected_exception(space, e)
interpreter\gateway.py:908:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.interpreter.gateway.BuiltinCodePassThroughArguments1 object at 0x00000264c0c80d40>
func = <FunctionWithFixedCode __call__>
w_obj = <W_TypeObject 'CDLL' at 0x264c15ddde0>
args = Arguments([W_BytesObject('missing\xff.so')])
def funcrun_obj(self, func, w_obj, args):
space = func.space
try:
> w_result = self.func__args__(space, w_obj, args)
interpreter\gateway.py:937:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'CDLL' at 0x264c15ddde0>
args = Arguments([W_BytesObject('missing\xff.so')])
def _call(space, w_obj, args):
self = space.descr_self_interp_w(self_type, w_obj)
> return func(self, space, args)
<284-codegen d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\rpython\tool\sourcetools.py:200>:4:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'CDLL' at 0x264c15ddde0>, space = StdObjSpace
__args__ = Arguments([W_BytesObject('missing\xff.so')])
def descr_call(self, space, __args__):
promote(self)
# invoke the __new__ of the type
if not we_are_jitted():
# note that the annotator will figure out that self.w_new_function
# can only be None if the newshortcut config option is not set
w_newfunc = self.w_new_function
else:
# for the JIT it is better to take the slow path because normal lookup
# is nicely optimized, but the self.w_new_function attribute is not
# known to the JIT
w_newfunc = None
if w_newfunc is None:
w_newtype, w_newdescr = self.lookup_where('__new__')
if w_newdescr is None: # see test_crash_mro_without_object_1
raise oefmt(space.w_TypeError, "cannot create '%N' instances",
self)
#
# issue #2666
if space.config.objspace.usemodules.cpyext:
w_newtype, w_newdescr = self.hack_which_new_to_call(
w_newtype, w_newdescr)
#
w_newfunc = space.get(w_newdescr, space.w_None, w_type=self)
if (space.config.objspace.std.newshortcut and
not we_are_jitted() and space._side_effects_ok() and
isinstance(w_newtype, W_TypeObject)):
self.w_new_function = w_newfunc
> w_newobject = space.call_obj_args(w_newfunc, self, __args__)
objspace\std\typeobject.py:750:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace, w_callable = <FunctionWithFixedCode __new__>
w_obj = <W_TypeObject 'CDLL' at 0x264c15ddde0>
args = Arguments([W_BytesObject('missing\xff.so')])
def call_obj_args(self, w_callable, w_obj, args):
if not self.config.objspace.disable_call_speedhacks:
# start of hack for performance
from pypy.interpreter.function import Function
if isinstance(w_callable, Function):
> return w_callable.call_obj_args(w_obj, args)
interpreter\baseobjspace.py:1232:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <FunctionWithFixedCode __new__>
w_obj = <W_TypeObject 'CDLL' at 0x264c15ddde0>
args = Arguments([W_BytesObject('missing\xff.so')])
def call_obj_args(self, w_obj, args):
# delegate activation to code
> w_res = self.getcode().funcrun_obj(self, w_obj, args)
interpreter\function.py:88:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.interpreter.gateway.BuiltinCode2 object at 0x00000264bf5fac98>
func = <FunctionWithFixedCode __new__>
w_obj = <W_TypeObject 'CDLL' at 0x264c15ddde0>
args = Arguments([W_BytesObject('missing\xff.so')])
def funcrun_obj(self, func, w_obj, args):
space = func.space
activation = self.activation
scope_w = args.parse_obj(w_obj, func.qualname, self.sig,
func.defs_w, func.w_kw_defs, self.minargs)
try:
w_result = activation._run(space, scope_w)
except DescrMismatch:
if w_obj is not None:
args = args.prepend(w_obj)
return self._type_unwrap_mismatch(space, args)
except Exception as e:
> self.handle_exception(space, e)
interpreter\gateway.py:884:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.interpreter.gateway.BuiltinCode2 object at 0x00000264bf5fac98>
space = StdObjSpace, e = ValueError('unichr() arg out of range',)
def handle_exception(self, space, e):
try:
if not we_are_translated():
raise
raise e
except OperationError:
raise
except Exception as e: # general fall-back
from pypy.interpreter import error
> raise error.get_converted_unexpected_exception(space, e)
interpreter\gateway.py:908:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.interpreter.gateway.BuiltinCode2 object at 0x00000264bf5fac98>
func = <FunctionWithFixedCode __new__>
w_obj = <W_TypeObject 'CDLL' at 0x264c15ddde0>
args = Arguments([W_BytesObject('missing\xff.so')])
def funcrun_obj(self, func, w_obj, args):
space = func.space
activation = self.activation
scope_w = args.parse_obj(w_obj, func.qualname, self.sig,
func.defs_w, func.w_kw_defs, self.minargs)
try:
> w_result = activation._run(space, scope_w)
interpreter\gateway.py:878:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.interpreter.gateway.BuiltinActivation_UwS_ObjSpace_W_Root_fsencode object at 0x00000264bf5fad08>
space = StdObjSpace
scope_w = [<W_TypeObject 'CDLL' at 0x264c15ddde0>, W_BytesObject('missing\xff.so')]
def _run(self, space, scope_w):
> return self.behavior(space, scope_w[0], space.fsencode_w(scope_w[1]))
<2108-codegen d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\rpython\tool\sourcetools.py:200>:3:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_type = <W_TypeObject 'CDLL' at 0x264c15ddde0>
name = 'missing\xff.so'
@unwrap_spec(name=name_spec)
def descr_new_cdll(space, w_type, name):
> cdll = open_cdll(space, name)
module\_rawffi\interp_rawffi.py:256:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, name = 'missing\xff.so'
def open_cdll(space, name):
try:
> return CDLL(name)
module\_rawffi\interp_rawffi.py:244:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <rpython.rlib.clibffi.CDLL object at 0x00000264c3bfb6a8>
libname = 'missing\xff.so', mode = -1
def __init__(self, libname, mode=-1):
"""Load the library, or raises DLOpenError."""
RawCDLL.__init__(self, rffi.cast(DLLHANDLE, -1))
> self.lib = dlopen(libname, mode)
..\rpython\rlib\clibffi.py:702:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
name = 'missing\xff.so', mode = -1
def dlopen(name, mode=-1):
# mode is unused on windows, but a consistant signature
if not name:
raise DLOpenError("cannot use None")
> with rffi.scoped_utf82wcharp(name, codepoints_in_utf8(name)) as buf:
..\rpython\rlib\rdynload.py:237:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <rpython.rtyper.lltypesystem.rffi.scoped_utf82wcharp instance at 0x00000264c3c3ba60>
value = 'missing\xff.so', unicode_len = 11
def __init__(self, value, unicode_len=-1):
from rpython.rlib import rutf8
if value is None:
self.buf = lltype.nullptr(CWCHARP.TO)
elif unicode_len < 0:
self.buf = utf82wcharp(value, rutf8.codepoints_in_utf8(value))
else:
> self.buf = utf82wcharp(value, unicode_len)
..\rpython\rtyper\lltypesystem\rffi.py:1438:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
utf8 = 'missing\xff.so', utf8len = 11, track_allocation = True
def utf82wcharp(utf8, utf8len, track_allocation=True):
from rpython.rlib import rutf8
if not we_are_translated():
assert utf8len == rutf8.codepoints_in_utf8(utf8)
# add 1 for the \x00, and another for cases where the last utf8 is an
# incomplete codepoint
if track_allocation:
w = lltype.malloc(CWCHARP.TO, utf8len + 2, flavor='raw', track_allocation=True)
else:
w = lltype.malloc(CWCHARP.TO, utf8len + 2, flavor='raw', track_allocation=False)
index = 0
for ch in rutf8.Utf8StringIterator(utf8):
> w[index] = unichr(ch)
E ValueError: unichr() arg out of range
..\rpython\rtyper\lltypesystem\rffi.py:1172: ValueError
---------------------------- Captured stderr call -----------------------------
Exception AssertionError: AssertionError(u'assert <Signed> == <INT>\n + where <Signed> = <function typeOf at 0x00000264bd8bcf20>(0)\n + where <function typeOf at 0x00000264bd8bcf20> = <function typeOf at 0x00000264bd8bcf20>\n + where <function typeOf at 0x00000264bd8bcf20> = lltype.typeOf',) in method __del__ of <rpython.rlib.rthread.Lock object at 0x00000264bd75ab48> ignored
Exception AssertionError: AssertionError(u'assert <Signed> == <INT>\n + where <Signed> = <function typeOf at 0x00000264bd8bcf20>(0)\n + where <function typeOf at 0x00000264bd8bcf20> = <function typeOf at 0x00000264bd8bcf20>\n + where <function typeOf at 0x00000264bd8bcf20> = lltype.typeOf',) in method __del__ of <rpython.rlib.rthread.Lock object at 0x00000264c37d4368> ignored
Exception AssertionError: AssertionError(u'assert <Signed> == <INT>\n + where <Signed> = <function typeOf at 0x00000264bd8bcf20>(0)\n + where <function typeOf at 0x00000264bd8bcf20> = <function typeOf at 0x00000264bd8bcf20>\n + where <function typeOf at 0x00000264bd8bcf20> = lltype.typeOf',) in method __del__ of <rpython.rlib.rthread.Lock object at 0x00000264c4341590> ignored
Exception AssertionError: AssertionError(u'assert <Signed> == <INT>\n + where <Signed> = <function typeOf at 0x00000264bd8bcf20>(0)\n + where <function typeOf at 0x00000264bd8bcf20> = <function typeOf at 0x00000264bd8bcf20>\n + where <function typeOf at 0x00000264bd8bcf20> = lltype.typeOf',) in method __del__ of <rpython.rlib.rthread.Lock object at 0x00000264c4952100> ignored
Exception AssertionError: AssertionError(u'assert <Signed> == <INT>\n + where <Signed> = <function typeOf at 0x00000264bd8bcf20>(0)\n + where <function typeOf at 0x00000264bd8bcf20> = <function typeOf at 0x00000264bd8bcf20>\n + where <function typeOf at 0x00000264bd8bcf20> = lltype.typeOf',) in method __del__ of <rpython.rlib.rthread.Lock object at 0x00000264c564cf38> ignored
Exception AssertionError: AssertionError(u'assert <Signed> == <INT>\n + where <Signed> = <function typeOf at 0x00000264bd8bcf20>(0)\n + where <function typeOf at 0x00000264bd8bcf20> = <function typeOf at 0x00000264bd8bcf20>\n + where <function typeOf at 0x00000264bd8bcf20> = lltype.typeOf',) in method __del__ of <rpython.rlib.rthread.Lock object at 0x00000264c5b25cc8> ignored
Exception AssertionError: AssertionError(u'assert <Signed> == <INT>\n + where <Signed> = <function typeOf at 0x00000264bd8bcf20>(0)\n + where <function typeOf at 0x00000264bd8bcf20> = <function typeOf at 0x00000264bd8bcf20>\n + where <function typeOf at 0x00000264bd8bcf20> = lltype.typeOf',) in method __del__ of <rpython.rlib.rthread.Lock object at 0x00000264c614f3d0> ignored
Exception AssertionError: AssertionError(u'assert <Signed> == <INT>\n + where <Signed> = <function typeOf at 0x00000264bd8bcf20>(0)\n + where <function typeOf at 0x00000264bd8bcf20> = <function typeOf at 0x00000264bd8bcf20>\n + where <function typeOf at 0x00000264bd8bcf20> = lltype.typeOf',) in method __del__ of <rpython.rlib.rthread.Lock object at 0x00000264c67c2e58> ignored
Exception AssertionError: AssertionError(u'assert <Signed> == <INT>\n + where <Signed> = <function typeOf at 0x00000264bd8bcf20>(0)\n + where <function typeOf at 0x00000264bd8bcf20> = <function typeOf at 0x00000264bd8bcf20>\n + where <function typeOf at 0x00000264bd8bcf20> = lltype.typeOf',) in method __del__ of <rpython.rlib.rthread.Lock object at 0x00000264c6bd2218> ignored
Exception AssertionError: AssertionError(u'assert <Signed> == <INT>\n + where <Signed> = <function typeOf at 0x00000264bd8bcf20>(0)\n + where <function typeOf at 0x00000264bd8bcf20> = <function typeOf at 0x00000264bd8bcf20>\n + where <function typeOf at 0x00000264bd8bcf20> = lltype.typeOf',) in method __del__ of <rpython.rlib.rthread.Lock object at 0x00000264c3e0f1a0> ignored
Exception AssertionError: AssertionError(u'assert <Signed> == <INT>\n + where <Signed> = <function typeOf at 0x00000264bd8bcf20>(0)\n + where <function typeOf at 0x00000264bd8bcf20> = <function typeOf at 0x00000264bd8bcf20>\n + where <function typeOf at 0x00000264bd8bcf20> = lltype.typeOf',) in method __del__ of <rpython.rlib.rthread.Lock object at 0x00000264c4207b08> ignored
Exception AssertionError: AssertionError(u'assert <Signed> == <INT>\n + where <Signed> = <function typeOf at 0x00000264bd8bcf20>(0)\n + where <function typeOf at 0x00000264bd8bcf20> = <function typeOf at 0x00000264bd8bcf20>\n + where <function typeOf at 0x00000264bd8bcf20> = lltype.typeOf',) in method __del__ of <rpython.rlib.rthread.Lock object at 0x00000264c52512f0> ignored
Exception AssertionError: AssertionError(u'assert <Signed> == <INT>\n + where <Signed> = <function typeOf at 0x00000264bd8bcf20>(0)\n + where <function typeOf at 0x00000264bd8bcf20> = <function typeOf at 0x00000264bd8bcf20>\n + where <function typeOf at 0x00000264bd8bcf20> = lltype.typeOf',) in method __del__ of <rpython.rlib.rthread.Lock object at 0x00000264c63f8800> ignored
Exception AssertionError: AssertionError(u'assert <Signed> == <INT>\n + where <Signed> = <function typeOf at 0x00000264bd8bcf20>(0)\n + where <function typeOf at 0x00000264bd8bcf20> = <function typeOf at 0x00000264bd8bcf20>\n + where <function typeOf at 0x00000264bd8bcf20> = lltype.typeOf',) in method __del__ of <rpython.rlib.rthread.Lock object at 0x00000264c7070b48> ignored
Exception AssertionError: AssertionError(u'assert <Signed> == <INT>\n + where <Signed> = <function typeOf at 0x00000264bd8bcf20>(0)\n + where <function typeOf at 0x00000264bd8bcf20> = <function typeOf at 0x00000264bd8bcf20>\n + where <function typeOf at 0x00000264bd8bcf20> = lltype.typeOf',) in method __del__ of <rpython.rlib.rthread.Lock object at 0x00000264c73de410> ignored
=========================== short test summary info ===========================
FAIL module\_rawffi\test\test__rawffi.py::AppTestFfi::()::test_libload_fail_nonutf8_name
============== 1 failed, 82 passed, 3 skipped in 157.75 seconds ===============
n: 2
Arg 0: 3
Arg 1: 15
++ 05:53:39 starting module/_vmprof/test [36 started in total]
__ module/_vmprof/test [33 done in total, somefailed=False] ___________________
============================= test session starts =============================
platform win32 -- Python 2.7.18[pypy-7.3.18-alpha], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('d:\\pypy_stuff\\buildbot64\\slave\\own-win-x86-64\\build\\pypy\\.hypothesis\\examples')
pytest-2.9.2 from d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pytest.pyc
rootdir: d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 0 items
======================== no tests ran in 0.00 seconds =========================
++ 05:53:41 starting module/_warnings/test [37 started in total]
__ module/_socket/test [34 done in total, somefailed=True] ____________________
============================= test session starts =============================
platform win32 -- Python 2.7.18[pypy-7.3.18-alpha], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('d:\\pypy_stuff\\buildbot64\\slave\\own-win-x86-64\\build\\pypy\\.hypothesis\\examples')
pytest-2.9.2 from d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pytest.pyc
rootdir: d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build, inifile: pytest.ini
plugins: hypothesis-4.39.3
[platform:msg] Updated environment with vsver 160, using x64 True
[platform:msg] Updated environment with vsver 160, using x64 True
collected 87 items
module\_socket\test\apptest_socket.py ..........ss.............F..F.....s...s.ss..s...s....s...sssss
module\_socket\test\test_sock_app.py .......s.........ss.s...
module\_socket\test\test_ztranslation.py .
================================== FAILURES ===================================
___________________________ test_recvmsg_issue2649 ____________________________
@pytest.mark.skipif(sys.platform == 'win32', reason="no recvmsg on win32")
@pytest.mark.skipif(sys.platform == 'darwin', reason="no MSG_ERRQUEUE on macos")
def test_recvmsg_issue2649():
import _socket as socket
listener = socket.socket(family=socket.AF_INET, type=socket.SOCK_DGRAM)
listener.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
listener.bind(('127.0.0.1', 1234))
s = socket.socket(family=socket.AF_INET, type=socket.SOCK_DGRAM)
s.sendto(b'x', ('127.0.0.1', 1234))
> with pytest.raises(BlockingIOError):
queue = s.recvmsg(1024, 1024, socket.MSG_ERRQUEUE)
E (application-level) AssertionError: raises() expected <class 'BlockingIOError'>, but got <class 'AttributeError'>
module\_socket\test\apptest_socket.py:334: AssertionError
__________________________ test_unix_socket_connect ___________________________
def test_unix_socket_connect():
> import _socket, os, tempfile
module\_socket\test\apptest_socket.py:373:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""Temporary files.
This module provides generic, low- and high-level interfaces for
creating temporary files and directories. All of the interfaces
provided by this module can be used without fear of race conditions
except for 'mktemp'. 'mktemp' is subject to race conditions and
should not be used; it is provided for backward compatibility only.
The default path names are returned as str. If you supply bytes as
input, all return values will be in bytes. Ex:
>>> tempfile.mkstemp()
(4, '/tmp/tmptpu9nin8')
>>> tempfile.mkdtemp(suffix=b'')
b'/tmp/tmppbi8f0hy'
This module also provides some data items to the user:
TMP_MAX - maximum number of names that will be tried before
giving up.
tempdir - If this is set to a string before the first use of
any routine from this module, it will be considered as
another candidate location to store temporary files.
"""
__all__ = [
"NamedTemporaryFile", "TemporaryFile", # high level safe interfaces
"SpooledTemporaryFile", "TemporaryDirectory",
"mkstemp", "mkdtemp", # low level safe interfaces
"mktemp", # deprecated unsafe interface
"TMP_MAX", "gettempprefix", # constants
"tempdir", "gettempdir",
"gettempprefixb", "gettempdirb",
]
# Imports.
import functools as _functools
import warnings as _warnings
import io as _io
import os as _os
> import shutil as _shutil
..\lib-python\3\tempfile.py:43:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""Utility functions for copying and archiving files and directory trees.
XXX The functions here don't copy the resource fork or other metadata on Mac.
"""
import os
import sys
import stat
import fnmatch
import collections
import errno
import warnings
try:
import zlib
del zlib
_ZLIB_SUPPORTED = True
except ImportError:
_ZLIB_SUPPORTED = False
try:
import bz2
del bz2
_BZ2_SUPPORTED = True
except ImportError:
_BZ2_SUPPORTED = False
try:
import lzma
del lzma
_LZMA_SUPPORTED = True
except ImportError:
_LZMA_SUPPORTED = False
_WINDOWS = os.name == 'nt'
posix = nt = None
if os.name == 'posix':
import posix
elif _WINDOWS:
import nt
if sys.platform == 'win32':
> import _winapi
..\lib-python\3\shutil.py:44:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
Support routines for subprocess and multiprocess module.
Currently, this extension module is only required when using the
modules on Windows.
"""
import sys
if sys.platform != 'win32':
raise ModuleNotFoundError("The '_winapi' module is only available on Windows", name="_winapi")
# Declare external Win32 functions
if sys.maxsize > 2 ** 31:
> from _pypy_winbase_cffi64 import ffi as _ffi
..\lib_pypy\_winapi.py:15:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
# auto-generated file
> import _cffi_backend
E (application-level) ModuleNotFoundError: No module named '_cffi_backend'
..\lib_pypy\_pypy_winbase_cffi64.py:2: ModuleNotFoundError
=========================== short test summary info ===========================
FAIL module\_socket\test\apptest_socket.py::test_recvmsg_issue2649
FAIL module\_socket\test\apptest_socket.py::test_unix_socket_connect
============== 2 failed, 67 passed, 18 skipped in 170.43 seconds ==============
++ 05:53:59 starting module/_weakref/test [38 started in total]
__ module/_warnings/test [35 done in total, somefailed=False] _________________
============================= test session starts =============================
platform win32 -- Python 2.7.18[pypy-7.3.18-alpha], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('d:\\pypy_stuff\\buildbot64\\slave\\own-win-x86-64\\build\\pypy\\.hypothesis\\examples')
pytest-2.9.2 from d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pytest.pyc
rootdir: d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build, inifile: pytest.ini
plugins: hypothesis-4.39.3
[platform:msg] Updated environment with vsver 160, using x64 True
[platform:msg] Updated environment with vsver 160, using x64 True
collected 22 items
module\_warnings\test\apptest_warnings.py ........s.s..........
module\_warnings\test\test_warnings.py .
==================== 20 passed, 2 skipped in 78.61 seconds ====================
++ 05:55:03 starting module/_winreg/test [39 started in total]
__ module/_sre/test [36 done in total, somefailed=False] ______________________
============================= test session starts =============================
platform win32 -- Python 2.7.18[pypy-7.3.18-alpha], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('d:\\pypy_stuff\\buildbot64\\slave\\own-win-x86-64\\build\\pypy\\.hypothesis\\examples')
pytest-2.9.2 from d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pytest.pyc
rootdir: d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build, inifile: pytest.ini
plugins: hypothesis-4.39.3
[platform:msg] Updated environment with vsver 160, using x64 True
[platform:msg] Updated environment with vsver 160, using x64 True
collected 163 items
module\_sre\test\apptest_sre.py .........................................................................................................
module\_sre\test\test_app_sre.py ..............................
module\_sre\test\test_sre_buf.py ............................
======================== 163 passed in 210.19 seconds =========================
++ 05:55:06 starting module/array/test [40 started in total]
__ module/_winreg/test [37 done in total, somefailed=True] ____________________
============================= test session starts =============================
platform win32 -- Python 2.7.18[pypy-7.3.18-alpha], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('d:\\pypy_stuff\\buildbot64\\slave\\own-win-x86-64\\build\\pypy\\.hypothesis\\examples')
pytest-2.9.2 from d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pytest.pyc
rootdir: d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 22 items
module\_winreg\test\test_winreg.py ..F...........s..ss...
================================== FAILURES ===================================
________________________ AppTestFfi.test_simple_write _________________________
self = <pypy.interpreter.typedef.W_ObjectObjectUserDictWeakrefable object at 0x0000022aaa1c2058>
def test_simple_write(self):
from winreg import SetValue, QueryValue, REG_SZ
value = u"Some Default value"
SetValue(self.root_key, self.test_key_name, REG_SZ, value)
> assert QueryValue(self.root_key, self.test_key_name) == value
E (application-level) AssertionError
[d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pypy\module\_winreg\test\test_winreg.py:76]:5: AssertionError
=========================== short test summary info ===========================
FAIL module\_winreg\test\test_winreg.py::AppTestFfi::()::test_simple_write
=============== 1 failed, 18 passed, 3 skipped in 43.18 seconds ===============
++ 05:55:49 starting module/atexit/test [41 started in total]
__ module/_weakref/test [38 done in total, somefailed=False] __________________
============================= test session starts =============================
platform win32 -- Python 2.7.18[pypy-7.3.18-alpha], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('d:\\pypy_stuff\\buildbot64\\slave\\own-win-x86-64\\build\\pypy\\.hypothesis\\examples')
pytest-2.9.2 from d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pytest.pyc
rootdir: d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build, inifile: pytest.ini
plugins: hypothesis-4.39.3
[platform:msg] Updated environment with vsver 160, using x64 True
[platform:msg] Updated environment with vsver 160, using x64 True
collected 43 items
module\_weakref\test\apptest_weakref.py ...........................................
========================= 43 passed in 112.75 seconds =========================
++ 05:55:57 starting module/binascii/test [42 started in total]
__ module/atexit/test [39 done in total, somefailed=False] ____________________
============================= test session starts =============================
platform win32 -- Python 2.7.18[pypy-7.3.18-alpha], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('d:\\pypy_stuff\\buildbot64\\slave\\own-win-x86-64\\build\\pypy\\.hypothesis\\examples')
pytest-2.9.2 from d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pytest.pyc
rootdir: d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build, inifile: pytest.ini
plugins: hypothesis-4.39.3
[platform:msg] Updated environment with vsver 160, using x64 True
[platform:msg] Updated environment with vsver 160, using x64 True
collected 2 items
module\atexit\test\apptest_atexit.py ..
========================== 2 passed in 52.19 seconds ==========================
++ 05:56:48 starting module/bz2/test [43 started in total]
__ module/binascii/test [40 done in total, somefailed=False] __________________
============================= test session starts =============================
platform win32 -- Python 2.7.18[pypy-7.3.18-alpha], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('d:\\pypy_stuff\\buildbot64\\slave\\own-win-x86-64\\build\\pypy\\.hypothesis\\examples')
pytest-2.9.2 from d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pytest.pyc
rootdir: d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 18 items
module\binascii\test\test_binascii.py ..................
========================= 18 passed in 67.57 seconds ==========================
++ 05:57:12 starting module/cmath/test [44 started in total]
__ module/bz2/test [41 done in total, somefailed=False] _______________________
============================= test session starts =============================
platform win32 -- Python 2.7.18[pypy-7.3.18-alpha], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('d:\\pypy_stuff\\buildbot64\\slave\\own-win-x86-64\\build\\pypy\\.hypothesis\\examples')
pytest-2.9.2 from d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pytest.pyc
rootdir: d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build, inifile: pytest.ini
plugins: hypothesis-4.39.3
[platform:msg] Updated environment with vsver 160, using x64 True
[platform:msg] Updated environment with vsver 160, using x64 True
collected 1 items / 3 skipped
module\bz2\test\test_large.py s
========================= 4 skipped in 60.13 seconds ==========================
++ 05:57:55 starting module/cpyext/test/test_api.py [45 started in total]
__ module/cmath/test [42 done in total, somefailed=False] _____________________
============================= test session starts =============================
platform win32 -- Python 2.7.18[pypy-7.3.18-alpha], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('d:\\pypy_stuff\\buildbot64\\slave\\own-win-x86-64\\build\\pypy\\.hypothesis\\examples')
pytest-2.9.2 from d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pytest.pyc
rootdir: d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 18 items
module\cmath\test\test_cmath.py ..................
========================= 18 passed in 43.60 seconds ==========================
++ 05:57:58 starting module/cpyext/test/test_arraymodule.py [46 started in total]
__ module/array/test [43 done in total, somefailed=True] ______________________
============================= test session starts =============================
platform win32 -- Python 2.7.18[pypy-7.3.18-alpha], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('d:\\pypy_stuff\\buildbot64\\slave\\own-win-x86-64\\build\\pypy\\.hypothesis\\examples')
pytest-2.9.2 from d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pytest.pyc
rootdir: d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build, inifile: pytest.ini
plugins: hypothesis-4.39.3
[platform:msg] Updated environment with vsver 160, using x64 True
[platform:msg] Updated environment with vsver 160, using x64 True
collected 64 items
module\array\test\apptest_array.py ...
module\array\test\test_array.py .....................s..................s................F..
module\array\test\test_ztranslation.py .
================================== FAILURES ===================================
___________________ AppTestArrayReconstructor.test_unicode ____________________
self = <pypy.interpreter.typedef.W_ObjectObjectUserDictWeakrefable object at 0x000001ea0f672330>
def test_unicode(self):
import array
array_reconstructor = array._array_reconstructor
UTF16_LE = 18
UTF16_BE = 19
UTF32_LE = 20
UTF32_BE = 21
teststr = "Bonne Journ\xe9e \U0002030a\U00020347"
testcases = (
(UTF16_LE, "UTF-16-LE"),
(UTF16_BE, "UTF-16-BE"),
(UTF32_LE, "UTF-32-LE"),
(UTF32_BE, "UTF-32-BE")
)
for testcase in testcases:
mformat_code, encoding = testcase
a = array.array('u', teststr)
b = array_reconstructor(
array.array, 'u', mformat_code, teststr.encode(encoding))
> assert a == b
E (application-level) AssertionError
[d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pypy\module\array\test\test_array.py:1269]:20: AssertionError
=========================== short test summary info ===========================
FAIL module\array\test\test_array.py::AppTestArrayReconstructor::()::test_unicode
============== 1 failed, 61 passed, 2 skipped in 173.04 seconds ===============
++ 05:58:02 starting module/cpyext/test/test_async_iter.py [47 started in total]
__ module/cpyext/test/test_api.py [44 done in total, somefailed=True] _________
[platform:msg] Updated environment with vsver 160, using x64 True
[platform:msg] Updated environment with vsver 160, using x64 True
============================= test session starts =============================
platform win32 -- Python 2.7.18[pypy-7.3.18-alpha], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('d:\\pypy_stuff\\buildbot64\\slave\\own-win-x86-64\\build\\pypy\\.hypothesis\\examples')
pytest-2.9.2 from d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pytest.pyc
rootdir: d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 4 items
module\cpyext\test\test_api.py EE..
=================================== ERRORS ====================================
______________ ERROR at setup of TestConversion.test_conversions ______________
item = <Function 'test_conversions'>
@pytest.hookimpl(tryfirst=True)
def pytest_runtest_setup(item):
if isinstance(item, pytest.Function):
config = item.config
if get_marker(item, name='pypy_only'):
if config.applevel is not None and not config.applevel.is_pypy:
pytest.skip('PyPy-specific test')
appclass = item.getparent(pytest.Class)
if appclass is not None:
from pypy.tool.pytest.objspace import gettestobjspace
# Make cls.space and cls.runappdirect available in tests.
spaceconfig = getattr(appclass.obj, 'spaceconfig', {})
> appclass.obj.space = gettestobjspace(**spaceconfig)
conftest.py:259:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
tool\pytest\objspace.py:24: in gettestobjspace
space = maketestobjspace(config)
tool\pytest\objspace.py:34: in maketestobjspace
space = make_objspace(config)
tool\option.py:33: in make_objspace
return StdObjSpace(config)
interpreter\baseobjspace.py:481: in __init__
self.initialize()
objspace\std\objspace.py:118: in initialize
self.setup_builtin_modules()
interpreter\baseobjspace.py:739: in setup_builtin_modules
self.fromcache(State).build_api()
module\cpyext\state.py:128: in build_api
self.api_lib = str(api.build_bridge(self.space))
module\cpyext\api.py:1468: in build_bridge
builder.attach_all(space)
module\cpyext\api.py:1535: in attach_all
attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1497: in attach_recursively
make_ref(space, w_type))
module\cpyext\pyobject.py:510: in make_ref
return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:483: in get_pyobj_and_incref
pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445: in as_pyobj
py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:326: in create_ref
track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:375: in track_reference
w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:132: in _cpyext_attach_pyobj
rawrefcount.create_link_pypy(self, py_obj)
..\rpython\rlib\rawrefcount.py:187: in create_link_pypy
assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:102: in _ob_link_get
return ob.c_ob_pypy_link
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1f6a4b83960>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x1f6a4b847a0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E 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 74.73 seconds ======================
++ 06:00:08 starting module/cpyext/test/test_boolobject.py [48 started in total]
__ module/cpyext/test/test_async_iter.py [45 done in total, somefailed=True] __
[platform:msg] Updated environment with vsver 160, using x64 True
[platform:msg] Updated environment with vsver 160, using x64 True
============================= test session starts =============================
platform win32 -- Python 2.7.18[pypy-7.3.18-alpha], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('d:\\pypy_stuff\\buildbot64\\slave\\own-win-x86-64\\build\\pypy\\.hypothesis\\examples')
pytest-2.9.2 from d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pytest.pyc
rootdir: d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 3 items
module\cpyext\test\test_async_iter.py EEE
=================================== ERRORS ====================================
______________ ERROR at setup of AppTestAsyncIter.test_asyncgen _______________
self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'>
func = <function <lambda> at 0x000002e37bc8f4c0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x000002e3751c1440>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000002e37d0fcee0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000002e3756866a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000002e3756866e0>]
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 0x000002e37d0fcee0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000002e3756866a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000002e3756866e0>]
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 0x000002e37c852c00>
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 0x000002e37c38b360>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000002e37c38b360>
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 0x000002e37b3eca68>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000002e37b3eca68>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000002e37b3eca68>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000002e37b3eca68>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000002e37b591ee0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000002e37c301248>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49d630a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49d63060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49d62ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000002e37a3f2f70>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x000002e37b3ed168>, <W_TypeObject 'GenericAlias' at 0x2e37cc17130>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2e37d662918>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2e37d662918>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2e37d662918>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2e37d662918>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2e37d713cd0>>
w_obj = <W_TypeObject 'ellipsis' at 0x2e37d662918>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x2e37d662918>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2e37d713cd0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x2e37d662918>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2e37d713cd0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2e37d713cd0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2e37d713cd0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x000002e300b054c0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x000002e3751c1440>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000002e37d0fcee0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000002e3756866a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000002e3756866e0>]
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 0x000002e37d0fcee0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000002e3756866a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000002e3756866e0>]
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 0x000002e3014caa20>
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 0x000002e3014ce3e0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000002e3014ce3e0>
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 0x000002e301483868>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000002e301483868>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000002e301483868>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000002e301483868>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000002e3019e6560>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000002e301b1da28>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe499530a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49953060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49952ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000002e37a3f2f70>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x000002e301483de0>, <W_TypeObject 'GenericAlias' at 0x2e37ca48918>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2e37c88bd00>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2e37c88bd00>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2e37c88bd00>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2e37c88bd00>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2e37d712b00>>
w_obj = <W_TypeObject 'ellipsis' at 0x2e37c88bd00>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x2e37c88bd00>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2e37d712b00>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x2e37c88bd00>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2e37d712b00>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2e37d712b00>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2e37d712b00>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x000002e37cc3e110>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x000002e3751c1440>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000002e37d0fcee0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000002e3756866a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000002e3756866e0>]
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 0x000002e37d0fcee0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000002e3756866a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000002e3756866e0>]
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 0x000002e37be84ef8>
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 0x000002e30101d120>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000002e30101d120>
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 0x000002e30103fc90>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000002e30103fc90>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000002e30103fc90>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000002e30103fc90>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000002e30065d320>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000002e301af6c28>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe498830a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49883060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49882ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000002e37a3f2f70>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x000002e3001e0250>, <W_TypeObject 'GenericAlias' at 0x2e37c9e1718>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2e37c0a49c0>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2e37c0a49c0>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2e37c0a49c0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2e37c0a49c0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2e37d7143f0>>
w_obj = <W_TypeObject 'ellipsis' at 0x2e37c0a49c0>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x2e37c0a49c0>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2e37d7143f0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x2e37c0a49c0>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2e37d7143f0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2e37d7143f0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2e37d7143f0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E 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 110.36 seconds ==========================
++ 06:00:44 starting module/cpyext/test/test_borrow.py [49 started in total]
__ module/cpyext/test/test_borrow.py [46 done in total, somefailed=True] ______
[platform:msg] Updated environment with vsver 160, using x64 True
[platform:msg] Updated environment with vsver 160, using x64 True
============================= test session starts =============================
platform win32 -- Python 2.7.18[pypy-7.3.18-alpha], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('d:\\pypy_stuff\\buildbot64\\slave\\own-win-x86-64\\build\\pypy\\.hypothesis\\examples')
pytest-2.9.2 from d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pytest.pyc
rootdir: d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 3 items
module\cpyext\test\test_borrow.py EEE
=================================== ERRORS ====================================
____________ ERROR at setup of AppTestBorrow.test_tuple_borrowing _____________
self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'>
func = <function <lambda> at 0x00000198f9db23e0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00000198f2eb33d0>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000198fadc0b60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000198f33766a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000198f33766e0>]
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 0x00000198fadc0b60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000198f33766a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000198f33766e0>]
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 0x00000198f9ab5768>
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 0x00000198fa1367e0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000198fa1367e0>
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 0x00000198f99d14e8>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00000198f99d14e8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00000198f99d14e8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00000198f99d14e8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00000198f9acdda0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00000198fa824d40>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe498840a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49884060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49883ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00000198f81721e0>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x00000198f99d1a60>, <W_TypeObject 'GenericAlias' at 0x198faa80058>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x198fb493398>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x198fb493398>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x198fb493398>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x198fb493398>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x198f953b570>>
w_obj = <W_TypeObject 'ellipsis' at 0x198fb493398>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x198fb493398>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x198f953b570>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x198fb493398>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x198f953b570>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x198f953b570>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x198f953b570>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00000198fd5411f0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00000198f2eb33d0>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000198fadc0b60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000198f33766a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000198f33766e0>]
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 0x00000198fadc0b60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000198f33766a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000198f33766e0>]
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 0x00000198fe007998>
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 0x00000198fdf8fe20>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000198fdf8fe20>
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 0x00000198fe02a560>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00000198fe02a560>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00000198fe02a560>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00000198fe02a560>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00000198fe32d7a0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00000198fae38d40>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe498040a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49804060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49803ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00000198f81721e0>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x00000198fe02aad8>, <W_TypeObject 'GenericAlias' at 0x198f91962c0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x198f4579408>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x198f4579408>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x198f4579408>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x198f4579408>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x198f953c740>>
w_obj = <W_TypeObject 'ellipsis' at 0x198f4579408>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x198f4579408>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x198f953c740>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x198f4579408>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x198f953c740>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x198f953c740>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x198f953c740>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00000198faa94890>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00000198f2eb33d0>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000198fadc0b60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000198f33766a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000198f33766e0>]
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 0x00000198fadc0b60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000198f33766a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000198f33766e0>]
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 0x00000198fbf16278>
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 0x00000198fc685c60>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000198fc685c60>
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 0x00000198fc6d2cd0>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00000198fc6d2cd0>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00000198fc6d2cd0>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00000198fc6d2cd0>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00000198fda6d320>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00000198fae78bf0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe498840a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49884060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49883ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00000198f81721e0>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x00000198fc6d3248>, <W_TypeObject 'GenericAlias' at 0x198f6216c98>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x198f8b59328>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x198f8b59328>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x198f8b59328>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x198f8b59328>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x198f953ce60>>
w_obj = <W_TypeObject 'ellipsis' at 0x198f8b59328>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x198f8b59328>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x198f953ce60>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x198f8b59328>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x198f953ce60>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x198f953ce60>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x198f953ce60>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E 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 111.53 seconds ==========================
++ 06:03:10 starting module/cpyext/test/test_buffer.py [50 started in total]
__ module/cpyext/test/test_boolobject.py [47 done in total, somefailed=True] __
[platform:msg] Updated environment with vsver 160, using x64 True
[platform:msg] Updated environment with vsver 160, using x64 True
============================= test session starts =============================
platform win32 -- Python 2.7.18[pypy-7.3.18-alpha], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('d:\\pypy_stuff\\buildbot64\\slave\\own-win-x86-64\\build\\pypy\\.hypothesis\\examples')
pytest-2.9.2 from d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pytest.pyc
rootdir: d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 4 items
module\cpyext\test\test_boolobject.py EEEE
=================================== ERRORS ====================================
_______________ ERROR at setup of TestBoolObject.test_fromlong ________________
item = <Function 'test_fromlong'>
@pytest.hookimpl(tryfirst=True)
def pytest_runtest_setup(item):
if isinstance(item, pytest.Function):
config = item.config
if get_marker(item, name='pypy_only'):
if config.applevel is not None and not config.applevel.is_pypy:
pytest.skip('PyPy-specific test')
appclass = item.getparent(pytest.Class)
if appclass is not None:
from pypy.tool.pytest.objspace import gettestobjspace
# Make cls.space and cls.runappdirect available in tests.
spaceconfig = getattr(appclass.obj, 'spaceconfig', {})
> appclass.obj.space = gettestobjspace(**spaceconfig)
conftest.py:259:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
tool\pytest\objspace.py:24: in gettestobjspace
space = maketestobjspace(config)
tool\pytest\objspace.py:34: in maketestobjspace
space = make_objspace(config)
tool\option.py:33: in make_objspace
return StdObjSpace(config)
interpreter\baseobjspace.py:481: in __init__
self.initialize()
objspace\std\objspace.py:118: in initialize
self.setup_builtin_modules()
interpreter\baseobjspace.py:739: in setup_builtin_modules
self.fromcache(State).build_api()
module\cpyext\state.py:128: in build_api
self.api_lib = str(api.build_bridge(self.space))
module\cpyext\api.py:1468: in build_bridge
builder.attach_all(space)
module\cpyext\api.py:1535: in attach_all
attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1497: in attach_recursively
make_ref(space, w_type))
module\cpyext\pyobject.py:510: in make_ref
return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:483: in get_pyobj_and_incref
pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445: in as_pyobj
py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:326: in create_ref
track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:375: in track_reference
w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:132: in _cpyext_attach_pyobj
rawrefcount.create_link_pypy(self, py_obj)
..\rpython\rlib\rawrefcount.py:187: in create_link_pypy
assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:102: in _ob_link_get
return ob.c_ob_pypy_link
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1ad4a35a8a0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x000001ad4f1c0020>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x000001ad44611440>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001ad4bd64de0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001ad44ad66a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001ad44ad66e0>]
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 0x000001ad4bd64de0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001ad44ad66a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001ad44ad66e0>]
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 0x000001ad4f1be1d8>
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 0x000001ad4f09fc20>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001ad4f09fc20>
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 0x000001ad4f1aa528>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001ad4f1aa528>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001ad4f1aa528>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000001ad4f1aa528>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000001ad4f3c7aa0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000001ad4bc98138>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe498440a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49844060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49843ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000001ad49131ef8>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x000001ad4f1aaaa0>, <W_TypeObject 'GenericAlias' at 0x1ad4a6754e8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1ad4b3dcd78>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1ad4b3dcd78>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1ad4b3dcd78>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1ad4b3dcd78>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1ad4a35d6f0>>
w_obj = <W_TypeObject 'ellipsis' at 0x1ad4b3dcd78>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x1ad4b3dcd78>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1ad4a35d6f0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x1ad4b3dcd78>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1ad4a35d6f0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1ad4a35d6f0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1ad4a35d6f0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x000001ad4b074ea8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x000001ad44611440>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001ad4bd64de0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001ad44ad66a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001ad44ad66e0>]
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 0x000001ad4bd64de0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001ad44ad66a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001ad44ad66e0>]
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 0x000001ad4e4e7ee8>
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 0x000001ad4d47abe0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001ad4d47abe0>
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 0x000001ad4d48d018>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001ad4d48d018>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001ad4d48d018>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000001ad4d48d018>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000001ad4f69c5a0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000001ad4a862560>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe498440a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49844060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49843ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000001ad49131ef8>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x000001ad4d48d590>, <W_TypeObject 'GenericAlias' at 0x1ad4a422e90>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1ad4b474b80>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1ad4b474b80>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1ad4b474b80>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1ad4b474b80>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1ad4a35afc0>>
w_obj = <W_TypeObject 'ellipsis' at 0x1ad4b474b80>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x1ad4b474b80>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1ad4a35afc0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x1ad4b474b80>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1ad4a35afc0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1ad4a35afc0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1ad4a35afc0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x000001ad4b5b6638>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x000001ad44611440>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001ad4bd64de0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001ad44ad66a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001ad44ad66e0>]
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 0x000001ad4bd64de0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001ad44ad66a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001ad44ad66e0>]
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 0x000001ad4c88f510>
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 0x000001ad4ee8ed60>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001ad4ee8ed60>
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 0x000001ad4ee927c8>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001ad4ee927c8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001ad4ee927c8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000001ad4ee927c8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000001ad4eb852e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000001ad49ac11d8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe498440a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49844060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49843ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000001ad49131ef8>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x000001ad4ee92d40>, <W_TypeObject 'GenericAlias' at 0x1ad4a81ead8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1ad4a564c60>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1ad4a564c60>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1ad4a564c60>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1ad4a564c60>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1ad4a35d360>>
w_obj = <W_TypeObject 'ellipsis' at 0x1ad4a564c60>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x1ad4a564c60>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1ad4a35d360>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x1ad4a564c60>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1ad4a35d360>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1ad4a35d360>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1ad4a35d360>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E 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 146.69 seconds ==========================
++ 06:03:10 starting module/cpyext/test/test_bytearrayobject.py [51 started in total]
__ module/cpyext/test/test_buffer.py [48 done in total, somefailed=True] ______
[platform:msg] Updated environment with vsver 160, using x64 True
[platform:msg] Updated environment with vsver 160, using x64 True
============================= test session starts =============================
platform win32 -- Python 2.7.18[pypy-7.3.18-alpha], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('d:\\pypy_stuff\\buildbot64\\slave\\own-win-x86-64\\build\\pypy\\.hypothesis\\examples')
pytest-2.9.2 from d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pytest.pyc
rootdir: d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 6 items
module\cpyext\test\test_buffer.py EEEEEE
=================================== ERRORS ====================================
____________ ERROR at setup of AppTestBuffer.test_size_from_format ____________
self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'>
func = <function <lambda> at 0x000002186e5b9100>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000021866481440>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000002186d9b2da0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000218669446a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000218669446e0>]
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 0x000002186d9b2da0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000218669446a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000218669446e0>]
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 0x000002186cf4d628>
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 0x000002186d5b57e0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000002186d5b57e0>
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 0x000002186d242c28>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000002186d242c28>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000002186d242c28>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000002186d242c28>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000002186b9ab260>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000002186df76f38>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe498430a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49843060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49842ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000002186afa9ad0>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x000002186d2431a0>, <W_TypeObject 'GenericAlias' at 0x2186d216a68>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2186e8aefa8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2186e8aefa8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2186e8aefa8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2186e8aefa8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2186c8dcf30>>
w_obj = <W_TypeObject 'ellipsis' at 0x2186e8aefa8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x2186e8aefa8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2186c8dcf30>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x2186e8aefa8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2186c8dcf30>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2186c8dcf30>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2186c8dcf30>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00000218715b44d0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000021866481440>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000002186d9b2da0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000218669446a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000218669446e0>]
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 0x000002186d9b2da0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000218669446a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000218669446e0>]
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 0x000002187162ecc8>
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 0x00000218715a5020>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000218715a5020>
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 0x0000021871636250>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000021871636250>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000021871636250>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000021871636250>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00000218718a6060>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00000218718c6020>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe498430a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49843060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49842ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000002186afa9ad0>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x00000218716367c8>, <W_TypeObject 'GenericAlias' at 0x2186c964c28>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x21867adec28>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x21867adec28>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x21867adec28>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x21867adec28>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2186c8dcba0>>
w_obj = <W_TypeObject 'ellipsis' at 0x21867adec28>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x21867adec28>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2186c8dcba0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x21867adec28>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2186c8dcba0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2186c8dcba0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2186c8dcba0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x0000021866d12f98>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000021866481440>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000002186d9b2da0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000218669446a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000218669446e0>]
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 0x000002186d9b2da0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000218669446a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000218669446e0>]
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 0x000002186c2faed0>
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 0x0000021870242360>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000021870242360>
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 0x000002187023e8a8>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000002187023e8a8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000002187023e8a8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000002187023e8a8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000021870fdbbe0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00000218718c63d8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe498b30a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe498b3060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe498b2ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000002186afa9ad0>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x000002187023ee20>, <W_TypeObject 'GenericAlias' at 0x2186cf86720>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2186cb979f0>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2186cb979f0>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2186cb979f0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2186cb979f0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2186c8dbd60>>
w_obj = <W_TypeObject 'ellipsis' at 0x2186cb979f0>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x2186cb979f0>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2186c8dbd60>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x2186cb979f0>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2186c8dbd60>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2186c8dbd60>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2186c8dbd60>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x000002186e0f2548>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000021866481440>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000002186d9b2da0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000218669446a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000218669446e0>]
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 0x000002186d9b2da0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000218669446a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000218669446e0>]
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 0x000002186e5f1a38>
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 0x0000021870740aa0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000021870740aa0>
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 0x0000021870736b80>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000021870736b80>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000021870736b80>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000021870736b80>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000002186fbaada0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000021869fd0608>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe498b30a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe498b3060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe498b2ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000002186afa9ad0>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x00000218707370f8>, <W_TypeObject 'GenericAlias' at 0x2186dffef70>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2186d12afa8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2186d12afa8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2186d12afa8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2186d12afa8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2186c8dc480>>
w_obj = <W_TypeObject 'ellipsis' at 0x2186d12afa8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x2186d12afa8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2186c8dc480>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x2186d12afa8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2186c8dc480>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2186c8dc480>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2186c8dc480>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x000002186f479f88>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000021866481440>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000002186d9b2da0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000218669446a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000218669446e0>]
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 0x000002186d9b2da0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000218669446a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000218669446e0>]
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 0x0000021870c916c8>
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 0x000002186f390060>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000002186f390060>
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 0x000002186f3a08e0>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000002186f3a08e0>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000002186f3a08e0>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000002186f3a08e0>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000002186ffbe6e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000021867d733d0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe498b30a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe498b3060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe498b2ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000002186afa9ad0>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x000002186f3a0e58>, <W_TypeObject 'GenericAlias' at 0x2186d081da8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2186d0314b0>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2186d0314b0>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2186d0314b0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2186d0314b0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2186c8dd2c0>>
w_obj = <W_TypeObject 'ellipsis' at 0x2186d0314b0>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x2186d0314b0>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2186c8dd2c0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x2186d0314b0>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2186c8dd2c0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2186c8dd2c0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2186c8dd2c0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x000002187198d178>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000021866481440>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000002186d9b2da0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000218669446a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000218669446e0>]
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 0x000002186d9b2da0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000218669446a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000218669446e0>]
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 0x000002186d57e200>
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 0x000002186f30bca0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000002186f30bca0>
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 0x000002186fa23b40>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000002186fa23b40>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000002186fa23b40>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000002186fa23b40>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000002186f661260>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000002186d2e23a0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe498b30a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe498b3060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe498b2ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000002186afa9ad0>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x000002186f668100>, <W_TypeObject 'GenericAlias' at 0x2186d22b868>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2186d1c61a8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2186d1c61a8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2186d1c61a8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2186d1c61a8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2186c8dd650>>
w_obj = <W_TypeObject 'ellipsis' at 0x2186d1c61a8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x2186d1c61a8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2186c8dd650>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x2186d1c61a8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2186c8dd650>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2186c8dd650>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2186c8dd650>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E 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 210.67 seconds ==========================
++ 06:07:18 starting module/cpyext/test/test_bytesobject.py [52 started in total]
__ module/cpyext/test/test_bytearrayobject.py [49 done in total, somefailed=True]
[platform:msg] Updated environment with vsver 160, using x64 True
[platform:msg] Updated environment with vsver 160, using x64 True
============================= test session starts =============================
platform win32 -- Python 2.7.18[pypy-7.3.18-alpha], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('d:\\pypy_stuff\\buildbot64\\slave\\own-win-x86-64\\build\\pypy\\.hypothesis\\examples')
pytest-2.9.2 from d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pytest.pyc
rootdir: d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 6 items
module\cpyext\test\test_bytearrayobject.py EEEEEE
=================================== ERRORS ====================================
______________ ERROR at setup of AppTestStringObject.test_basic _______________
self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'>
func = <function <lambda> at 0x0000018b14f52c50>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000018b0cfa3440>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000018b14512660>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000018b0d466660>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000018b0d4666a0>]
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 0x0000018b14512660>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000018b0d466660>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000018b0d4666a0>]
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 0x0000018b12c5ab10>
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 0x0000018b140315e0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000018b140315e0>
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 0x0000018b13cc97f8>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000018b13cc97f8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000018b13cc97f8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000018b13cc97f8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000018b13683220>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000018b145cfe18>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe498030a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49803060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49802ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000018b11a88de8>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x0000018b13cc9f30>, <W_TypeObject 'GenericAlias' at 0x18b14af87c8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x18b15276bf0>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x18b15276bf0>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x18b15276bf0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x18b15276bf0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x18b12fe0660>>
w_obj = <W_TypeObject 'ellipsis' at 0x18b15276bf0>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x18b15276bf0>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x18b12fe0660>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x18b15276bf0>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x18b12fe0660>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x18b12fe0660>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x18b12fe0660>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x0000018b17d40548>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000018b0cfa3440>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000018b14512660>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000018b0d466660>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000018b0d4666a0>]
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 0x0000018b14512660>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000018b0d466660>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000018b0d4666a0>]
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 0x0000018b17da1c18>
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 0x0000018b17d8c860>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000018b17d8c860>
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 0x0000018b17d9cc98>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000018b17d9cc98>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000018b17d9cc98>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000018b17d9cc98>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000018b181aa560>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000018b145ce678>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe498430a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49843060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49842ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000018b11a88de8>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x0000018b17d9d210>, <W_TypeObject 'GenericAlias' at 0x18b13b06950>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x18b131dd440>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x18b131dd440>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x18b131dd440>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x18b131dd440>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x18b12fe2d90>>
w_obj = <W_TypeObject 'ellipsis' at 0x18b131dd440>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x18b131dd440>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x18b12fe2d90>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x18b131dd440>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x18b12fe2d90>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x18b12fe2d90>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x18b12fe2d90>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x0000018b1250a980>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000018b0cfa3440>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000018b14512660>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000018b0d466660>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000018b0d4666a0>]
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 0x0000018b14512660>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000018b0d466660>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000018b0d4666a0>]
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 0x0000018b15524430>
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 0x0000018b177692e0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000018b177692e0>
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 0x0000018b1776aad8>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000018b1776aad8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000018b1776aad8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000018b1776aad8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000018b16266ca0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000018b14b23248>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe498f30a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe498f3060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe498f2ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000018b11a88de8>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x0000018b1776b050>, <W_TypeObject 'GenericAlias' at 0x18b12e93088>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x18b12dcf3d0>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x18b12dcf3d0>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x18b12dcf3d0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x18b12dcf3d0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x18b12fe1830>>
w_obj = <W_TypeObject 'ellipsis' at 0x18b12dcf3d0>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x18b12dcf3d0>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x18b12fe1830>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x18b12dcf3d0>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x18b12fe1830>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x18b12fe1830>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x18b12fe1830>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x0000018b129fc098>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000018b0cfa3440>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000018b14512660>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000018b0d466660>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000018b0d4666a0>]
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 0x0000018b14512660>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000018b0d466660>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000018b0d4666a0>]
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 0x0000018b121cca70>
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 0x0000018b16183520>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000018b16183520>
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 0x0000018b161b5bb0>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000018b161b5bb0>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000018b161b5bb0>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000018b161b5bb0>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000018b1705e360>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000018b12f4b600>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe498f30a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe498f3060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe498f2ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000018b11a88de8>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x0000018b16398170>, <W_TypeObject 'GenericAlias' at 0x18b13e91d70>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x18b13ba64f0>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x18b13ba64f0>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x18b13ba64f0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x18b13ba64f0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x18b12fe2a00>>
w_obj = <W_TypeObject 'ellipsis' at 0x18b13ba64f0>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x18b13ba64f0>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x18b12fe2a00>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x18b13ba64f0>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x18b12fe2a00>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x18b12fe2a00>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x18b12fe2a00>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x0000018b183b0d40>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000018b0cfa3440>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000018b14512660>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000018b0d466660>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000018b0d4666a0>]
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 0x0000018b14512660>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000018b0d466660>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000018b0d4666a0>]
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 0x0000018b14074e80>
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 0x0000018b179026e0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000018b179026e0>
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 0x0000018b178af088>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000018b178af088>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000018b178af088>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000018b178af088>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000018b16604320>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000018b131c6448>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe498f30a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe498f3060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe498f2ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000018b11a88de8>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x0000018b178af7c0>, <W_TypeObject 'GenericAlias' at 0x18b13681b40>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x18b13ea4100>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x18b13ea4100>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x18b13ea4100>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x18b13ea4100>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x18b12fe3120>>
w_obj = <W_TypeObject 'ellipsis' at 0x18b13ea4100>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x18b13ea4100>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x18b12fe3120>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x18b13ea4100>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x18b12fe3120>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x18b12fe3120>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x18b12fe3120>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x0000018b14f5b448>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000018b0cfa3440>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000018b14512660>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000018b0d466660>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000018b0d4666a0>]
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 0x0000018b14512660>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000018b0d466660>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000018b0d4666a0>]
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 0x0000018b1536c548>
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 0x0000018b17862da0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000018b17862da0>
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 0x0000018b17830288>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000018b17830288>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000018b17830288>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000018b17830288>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000018b17722f60>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000018b13cafc20>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe498f30a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe498f3060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe498f2ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000018b11a88de8>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x0000018b17830800>, <W_TypeObject 'GenericAlias' at 0x18b12571cc8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x18b13e68448>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x18b13e68448>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x18b13e68448>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x18b13e68448>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x18b12fe14a0>>
w_obj = <W_TypeObject 'ellipsis' at 0x18b13e68448>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x18b13e68448>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x18b12fe14a0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x18b13e68448>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x18b12fe14a0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x18b12fe14a0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x18b12fe14a0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E 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 209.71 seconds ==========================
++ 06:07:18 starting module/cpyext/test/test_capsule.py [53 started in total]
__ module/cpyext/test/test_arraymodule.py [50 done in total, somefailed=True] _
[platform:msg] Updated environment with vsver 160, using x64 True
[platform:msg] Updated environment with vsver 160, using x64 True
============================= test session starts =============================
platform win32 -- Python 2.7.18[pypy-7.3.18-alpha], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('d:\\pypy_stuff\\buildbot64\\slave\\own-win-x86-64\\build\\pypy\\.hypothesis\\examples')
pytest-2.9.2 from d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pytest.pyc
rootdir: d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 18 items
module\cpyext\test\test_arraymodule.py EEEEEEEEEEEEEEEEEE
=================================== ERRORS ====================================
_______________ ERROR at setup of AppTestArrayModule.test_basic _______________
self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'>
func = <function <lambda> at 0x000001e0360689f8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x000001e0300d33d0>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001e03776fc60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001e0305946a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001e0305946e0>]
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 0x000001e03776fc60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001e0305946a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001e0305946e0>]
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 0x000001e036ccca98>
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 0x000001e037268560>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001e037268560>
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 0x000001e030331248>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001e030331248>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001e030331248>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000001e030331248>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000001e036a3cb60>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000001e036041d70>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe499930a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49993060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49992ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000001e034c29b08>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x000001e033a351a0>, <W_TypeObject 'GenericAlias' at 0x1e036f5f6a8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1e038536870>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1e038536870>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1e038536870>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1e038536870>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0359e1b10>>
w_obj = <W_TypeObject 'ellipsis' at 0x1e038536870>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x1e038536870>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0359e1b10>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x1e038536870>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0359e1b10>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0359e1b10>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0359e1b10>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x000001e03b7d2638>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x000001e0300d33d0>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001e03776fc60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001e0305946a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001e0305946e0>]
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 0x000001e03776fc60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001e0305946a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001e0305946e0>]
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 0x000001e03b87f470>
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 0x000001e03b7a7f20>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001e03b7a7f20>
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 0x000001e03b882598>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001e03b882598>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001e03b882598>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000001e03b882598>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000001e03ba3d2a0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000001e03bc3d440>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe499530a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49953060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49952ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000001e034c29b08>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x000001e03b882b10>, <W_TypeObject 'GenericAlias' at 0x1e036205360>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1e035f55da8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1e035f55da8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1e035f55da8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1e035f55da8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0359e3eb0>>
w_obj = <W_TypeObject 'ellipsis' at 0x1e035f55da8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x1e035f55da8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0359e3eb0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x1e035f55da8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0359e3eb0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0359e3eb0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0359e3eb0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x000001e03250cea8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x000001e0300d33d0>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001e03776fc60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001e0305946a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001e0305946e0>]
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 0x000001e03776fc60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001e0305946a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001e0305946e0>]
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 0x000001e037329d30>
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 0x000001e03afac660>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001e03afac660>
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 0x000001e03b303590>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001e03b303590>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001e03b303590>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000001e03b303590>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000001e03a913c20>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000001e03bc3c368>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe498830a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49883060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49882ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000001e034c29b08>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x000001e03b303b08>, <W_TypeObject 'GenericAlias' at 0x1e0361c10c0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1e0353dee20>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1e0353dee20>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1e0353dee20>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1e0353dee20>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0359e0cd0>>
w_obj = <W_TypeObject 'ellipsis' at 0x1e0353dee20>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x1e0353dee20>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0359e0cd0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x1e0353dee20>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0359e0cd0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0359e0cd0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0359e0cd0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x000001e037293718>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x000001e0300d33d0>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001e03776fc60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001e0305946a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001e0305946e0>]
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 0x000001e03776fc60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001e0305946a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001e0305946e0>]
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 0x000001e037e4cf98>
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 0x000001e039e97da0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001e039e97da0>
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 0x000001e0399ab558>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001e0399ab558>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001e0399ab558>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000001e0399ab558>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000001e03b5f9960>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000001e036de31d8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe498830a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49883060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49882ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000001e034c29b08>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x000001e0399abad0>, <W_TypeObject 'GenericAlias' at 0x1e0381a32f0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1e036eaa950>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1e036eaa950>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1e036eaa950>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1e036eaa950>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0359e1060>>
w_obj = <W_TypeObject 'ellipsis' at 0x1e036eaa950>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x1e036eaa950>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0359e1060>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x1e036eaa950>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0359e1060>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0359e1060>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0359e1060>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x000001e03acc1f88>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x000001e0300d33d0>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001e03776fc60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001e0305946a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001e0305946e0>]
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 0x000001e03776fc60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001e0305946a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001e0305946e0>]
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 0x000001e03ace5a38>
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 0x000001e03a845060>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001e03a845060>
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 0x000001e03a1ef168>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001e03a1ef168>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001e03a1ef168>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000001e03a1ef168>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000001e039f873a0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000001e035db3d38>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe498430a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49843060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49842ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000001e034c29b08>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x000001e03a1ef8d8>, <W_TypeObject 'GenericAlias' at 0x1e037aee870>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1e0381aefa8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1e0381aefa8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1e0381aefa8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1e0381aefa8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0359e3790>>
w_obj = <W_TypeObject 'ellipsis' at 0x1e0381aefa8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x1e0381aefa8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0359e3790>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x1e0381aefa8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0359e3790>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0359e3790>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0359e3790>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x000001e03bb855b0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x000001e0300d33d0>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001e03776fc60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001e0305946a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001e0305946e0>]
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 0x000001e03776fc60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001e0305946a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001e0305946e0>]
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 0x000001e0365c9060>
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 0x000001e03ad62220>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001e03ad62220>
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 0x000001e03b16fd70>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001e03b16fd70>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001e03b16fd70>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000001e03b16fd70>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000001e03ad63520>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000001e037f3f360>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe498430a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49843060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49842ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000001e034c29b08>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x000001e03ad26330>, <W_TypeObject 'GenericAlias' at 0x1e0374fe8a8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1e036f36c98>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1e036f36c98>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1e036f36c98>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1e036f36c98>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0359e05b0>>
w_obj = <W_TypeObject 'ellipsis' at 0x1e036f36c98>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x1e036f36c98>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0359e05b0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x1e036f36c98>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0359e05b0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0359e05b0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0359e05b0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x000001e0358e3010>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x000001e0300d33d0>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001e03776fc60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001e0305946a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001e0305946e0>]
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 0x000001e03776fc60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001e0305946a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001e0305946e0>]
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 0x000001e037b04548>
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 0x000001e0396322a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001e0396322a0>
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 0x000001e039676f00>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001e039676f00>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001e039676f00>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000001e039676f00>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000001e039633520>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000001e037b1b8d8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe498430a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49843060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49842ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000001e034c29b08>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x000001e039677478>, <W_TypeObject 'GenericAlias' at 0x1e03813c640>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1e037aef910>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1e037aef910>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1e037aef910>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1e037aef910>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0359e1780>>
w_obj = <W_TypeObject 'ellipsis' at 0x1e037aef910>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x1e037aef910>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0359e1780>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x1e037aef910>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0359e1780>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0359e1780>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0359e1780>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x000001e036bcf9e8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x000001e0300d33d0>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001e03776fc60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001e0305946a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001e0305946e0>]
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 0x000001e03776fc60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001e0305946a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001e0305946e0>]
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 0x000001e0372b6fc0>
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 0x000001e03a53f820>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001e03a53f820>
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 0x000001e03a4f12f0>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001e03a4f12f0>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001e03a4f12f0>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000001e03a4f12f0>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000001e03a034c20>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000001e037760838>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe498830a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49883060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49882ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000001e034c29b08>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x000001e03a4f1868>, <W_TypeObject 'GenericAlias' at 0x1e0378134e8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1e036f0bd70>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1e036f0bd70>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1e036f0bd70>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1e036f0bd70>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0359e1ea0>>
w_obj = <W_TypeObject 'ellipsis' at 0x1e036f0bd70>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x1e036f0bd70>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0359e1ea0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x1e036f0bd70>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0359e1ea0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0359e1ea0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0359e1ea0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x000001e036ca74c0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x000001e0300d33d0>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001e03776fc60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001e0305946a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001e0305946e0>]
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 0x000001e03776fc60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001e0305946a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001e0305946e0>]
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 0x000001e03abde700>
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 0x000001e03ad59220>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001e03ad59220>
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 0x000001e03ad0d8d8>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001e03ad0d8d8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001e03ad0d8d8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000001e03ad0d8d8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000001e039ed8ba0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000001e034dd6ec8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe498830a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49883060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49882ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000001e034c29b08>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x000001e03ad0de50>, <W_TypeObject 'GenericAlias' at 0x1e0372aade8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1e0381ae7c8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1e0381ae7c8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1e0381ae7c8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1e0381ae7c8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0359e2950>>
w_obj = <W_TypeObject 'ellipsis' at 0x1e0381ae7c8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x1e0381ae7c8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0359e2950>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x1e0381ae7c8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0359e2950>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0359e2950>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0359e2950>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x000001e036b4b628>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x000001e0300d33d0>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001e03776fc60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001e0305946a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001e0305946e0>]
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 0x000001e03776fc60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001e0305946a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001e0305946e0>]
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 0x000001e03682fe98>
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 0x000001e03a436b60>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001e03a436b60>
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 0x000001e03a4011d8>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001e03a4011d8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001e03a4011d8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000001e03a4011d8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000001e03a437d20>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000001e03a206330>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe498430a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49843060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49842ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000001e034c29b08>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x000001e03a401750>, <W_TypeObject 'GenericAlias' at 0x1e0372aa790>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1e036f2d6e0>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1e036f2d6e0>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1e036f2d6e0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1e036f2d6e0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0359e2ce0>>
w_obj = <W_TypeObject 'ellipsis' at 0x1e036f2d6e0>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x1e036f2d6e0>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0359e2ce0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x1e036f2d6e0>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0359e2ce0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0359e2ce0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0359e2ce0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x000001e036dc74c0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x000001e0300d33d0>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001e03776fc60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001e0305946a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001e0305946e0>]
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 0x000001e03776fc60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001e0305946a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001e0305946e0>]
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 0x000001e0381edda8>
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 0x000001e039688fe0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001e039688fe0>
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 0x000001e0399fa218>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001e0399fa218>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001e0399fa218>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000001e0399fa218>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000001e03ad2e320>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000001e037216288>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe498830a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49883060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49882ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000001e034c29b08>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x000001e0399fa790>, <W_TypeObject 'GenericAlias' at 0x1e0372aa9c0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1e036f08ad8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1e036f08ad8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1e036f08ad8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1e036f08ad8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0311f8f30>>
w_obj = <W_TypeObject 'ellipsis' at 0x1e036f08ad8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x1e036f08ad8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0311f8f30>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x1e036f08ad8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0311f8f30>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0311f8f30>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0311f8f30>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x000001e03ac0ad40>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x000001e0300d33d0>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001e03776fc60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001e0305946a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001e0305946e0>]
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 0x000001e03776fc60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001e0305946a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001e0305946e0>]
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 0x000001e0375900e8>
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 0x000001e03934c5a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001e03934c5a0>
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 0x000001e03933a0c8>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001e03933a0c8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001e03933a0c8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000001e03933a0c8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000001e03934d6e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000001e0372161a8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe498f30a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe498f3060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe498f2ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000001e034c29b08>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x000001e03933a640>, <W_TypeObject 'GenericAlias' at 0x1e038125980>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1e036f7ba98>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1e036f7ba98>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1e036f7ba98>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1e036f7ba98>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0311fa100>>
w_obj = <W_TypeObject 'ellipsis' at 0x1e036f7ba98>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x1e036f7ba98>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0311fa100>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x1e036f7ba98>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0311fa100>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0311fa100>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0311fa100>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x000001e03bade5c0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x000001e0300d33d0>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001e03776fc60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001e0305946a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001e0305946e0>]
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 0x000001e03776fc60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001e0305946a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001e0305946e0>]
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 0x000001e03ab24b60>
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 0x000001e03a6455a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001e03a6455a0>
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 0x000001e0395c5520>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001e0395c5520>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001e0395c5520>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000001e0395c5520>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000001e039eda8e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000001e03a50a800>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe498f30a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe498f3060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe498f2ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000001e034c29b08>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x000001e0395c5a98>, <W_TypeObject 'GenericAlias' at 0x1e0375a1248>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1e036f97f30>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1e036f97f30>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1e036f97f30>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1e036f97f30>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0359e3070>>
w_obj = <W_TypeObject 'ellipsis' at 0x1e036f97f30>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x1e036f97f30>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0359e3070>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x1e036f97f30>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0359e3070>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0359e3070>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0359e3070>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x000001e03bc2e9f8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x000001e0300d33d0>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001e03776fc60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001e0305946a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001e0305946e0>]
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 0x000001e03776fc60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001e0305946a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001e0305946e0>]
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 0x000001e0368ff448>
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 0x000001e03a652a60>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001e03a652a60>
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 0x000001e03a657a98>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001e03a657a98>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001e03a657a98>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000001e03a657a98>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000001e03a653c60>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000001e03a7bd130>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe498f30a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe498f3060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe498f2ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000001e034c29b08>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x000001e03960c1a8>, <W_TypeObject 'GenericAlias' at 0x1e0382ed0f8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1e037381210>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1e037381210>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1e037381210>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1e037381210>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0311fa820>>
w_obj = <W_TypeObject 'ellipsis' at 0x1e037381210>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x1e037381210>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0311fa820>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x1e037381210>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0311fa820>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0311fa820>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0311fa820>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x000001e031f2c548>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x000001e0300d33d0>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001e03776fc60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001e0305946a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001e0305946e0>]
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 0x000001e03776fc60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001e0305946a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001e0305946e0>]
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 0x000001e037d685c0>
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 0x000001e03a1d4fa0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001e03a1d4fa0>
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 0x000001e03a1dd670>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001e03a1dd670>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001e03a1dd670>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000001e03a1dd670>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000001e03a12a4e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000001e037812020>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe498f30a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe498f3060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe498f2ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000001e034c29b08>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x000001e03b30b600>, <W_TypeObject 'GenericAlias' at 0x1e03842b4e8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1e036f973d0>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1e036f973d0>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1e036f973d0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1e036f973d0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0377b6c80>>
w_obj = <W_TypeObject 'ellipsis' at 0x1e036f973d0>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x1e036f973d0>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0377b6c80>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x1e036f973d0>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0377b6c80>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0377b6c80>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0377b6c80>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x000001e037acdcb8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x000001e0300d33d0>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001e03776fc60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001e0305946a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001e0305946e0>]
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 0x000001e03776fc60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001e0305946a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001e0305946e0>]
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 0x000001e0375ba458>
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 0x000001e03967e1a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001e03967e1a0>
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 0x000001e0396200c8>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001e0396200c8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001e0396200c8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000001e0396200c8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000001e03967f2a0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000001e0373e11d8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe498b30a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe498b3060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe498b2ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000001e034c29b08>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x000001e039620640>, <W_TypeObject 'GenericAlias' at 0x1e03757cb80>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1e036f2d2f0>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1e036f2d2f0>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1e036f2d2f0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1e036f2d2f0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0377b5000>>
w_obj = <W_TypeObject 'ellipsis' at 0x1e036f2d2f0>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x1e036f2d2f0>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0377b5000>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x1e036f2d2f0>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0377b5000>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0377b5000>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0377b5000>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x000001e03ac0a3e0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x000001e0300d33d0>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001e03776fc60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001e0305946a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001e0305946e0>]
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 0x000001e03776fc60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001e0305946a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001e0305946e0>]
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 0x000001e03ab88b10>
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 0x000001e03a0ab520>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001e03a0ab520>
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 0x000001e0395ee560>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001e0395ee560>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001e0395ee560>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000001e0395ee560>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000001e03b0ec7e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000001e03a165248>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe498b30a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe498b3060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe498b2ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000001e034c29b08>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x000001e0395eead8>, <W_TypeObject 'GenericAlias' at 0x1e038562ad8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1e0375e3210>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1e0375e3210>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1e0375e3210>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1e0375e3210>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0377b61d0>>
w_obj = <W_TypeObject 'ellipsis' at 0x1e0375e3210>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x1e0375e3210>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0377b61d0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x1e0375e3210>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0377b61d0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0377b61d0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0377b61d0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x000001e03badf880>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x000001e0300d33d0>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001e03776fc60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001e0305946a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001e0305946e0>]
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 0x000001e03776fc60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001e0305946a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001e0305946e0>]
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 0x000001e03680bc40>
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 0x000001e03bca3ae0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001e03bca3ae0>
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 0x000001e039f1ef38>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001e039f1ef38>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001e039f1ef38>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000001e039f1ef38>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000001e039f08ca0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000001e0376e6f00>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe498b30a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe498b3060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe498b2ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000001e034c29b08>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x000001e039f1f4b0>, <W_TypeObject 'GenericAlias' at 0x1e039495980>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1e036f96c28>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1e036f96c28>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1e036f96c28>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1e036f96c28>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0377b7010>>
w_obj = <W_TypeObject 'ellipsis' at 0x1e036f96c28>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x1e036f96c28>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0377b7010>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x1e036f96c28>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0377b7010>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0377b7010>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0377b7010>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E 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 625.17 seconds ==========================
++ 06:09:21 starting module/cpyext/test/test_cell.py [54 started in total]
__ module/cpyext/test/test_capsule.py [51 done in total, somefailed=True] _____
[platform:msg] Updated environment with vsver 160, using x64 True
[platform:msg] Updated environment with vsver 160, using x64 True
============================= test session starts =============================
platform win32 -- Python 2.7.18[pypy-7.3.18-alpha], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('d:\\pypy_stuff\\buildbot64\\slave\\own-win-x86-64\\build\\pypy\\.hypothesis\\examples')
pytest-2.9.2 from d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pytest.pyc
rootdir: d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 3 items
module\cpyext\test\test_capsule.py EEE
=================================== ERRORS ====================================
____________ ERROR at setup of AppTestCapsule.test_capsule_import _____________
self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'>
func = <function <lambda> at 0x0000020f9d93cb60>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000020f956b1440>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000020f9cf4a820>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000020f95b766a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000020f95b766e0>]
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 0x0000020f9cf4a820>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000020f95b766a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000020f95b766e0>]
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 0x0000020f9c64ed90>
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 0x0000020f9c8e20a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000020f9c8e20a0>
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 0x0000020f9c4fbc90>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000020f9c4fbc90>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000020f9c4fbc90>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000020f9c4fbc90>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000020f9c0e9ea0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000020f9ca05478>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe498b30a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe498b3060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe498b2ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000020f9a3dc6e8>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x0000020f9c4dc250>, <W_TypeObject 'GenericAlias' at 0x20f9ba27f30>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x20f9e3703d8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x20f9e3703d8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x20f9e3703d8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x20f9e3703d8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x20f98f42780>>
w_obj = <W_TypeObject 'ellipsis' at 0x20f9e3703d8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x20f9e3703d8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x20f98f42780>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x20f9e3703d8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x20f98f42780>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x20f98f42780>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x20f98f42780>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x0000020f9fbd9c40>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000020f956b1440>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000020f9cf4a820>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000020f95b766a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000020f95b766e0>]
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 0x0000020f9cf4a820>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000020f95b766a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000020f95b766e0>]
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 0x0000020fa0772a20>
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 0x0000020fa07670a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000020fa07670a0>
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 0x0000020fa07701e0>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000020fa07701e0>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000020fa07701e0>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000020fa07701e0>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000020fa0a65ae0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000020fa0c88f00>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe498f30a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe498f3060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe498f2ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000020f9a3dc6e8>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x0000020fa0770758>, <W_TypeObject 'GenericAlias' at 0x20f98e1fb40>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x20f9c380b10>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x20f9c380b10>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x20f9c380b10>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x20f9c380b10>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x20f98f415b0>>
w_obj = <W_TypeObject 'ellipsis' at 0x20f9c380b10>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x20f9c380b10>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x20f98f415b0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x20f9c380b10>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x20f98f415b0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x20f98f415b0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x20f98f415b0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x0000020f9c636368>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000020f956b1440>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000020f9cf4a820>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000020f95b766a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000020f95b766e0>]
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 0x0000020f9cf4a820>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000020f95b766a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000020f95b766e0>]
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 0x0000020f9d6e64d0>
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 0x0000020fa01e81e0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000020fa01e81e0>
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 0x0000020fa01f8330>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000020fa01f8330>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000020fa01f8330>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000020fa01f8330>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000020f9ee771e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000020fa0a16218>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe498b30a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe498b3060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe498b2ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000020f9a3dc6e8>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x0000020fa01f88a8>, <W_TypeObject 'GenericAlias' at 0x20f9c698aa0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x20f9b48ab48>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x20f9b48ab48>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x20f9b48ab48>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x20f9b48ab48>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x20f98f41cd0>>
w_obj = <W_TypeObject 'ellipsis' at 0x20f9b48ab48>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x20f9b48ab48>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x20f98f41cd0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x20f9b48ab48>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x20f98f41cd0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x20f98f41cd0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x20f98f41cd0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E 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 110.31 seconds ==========================
++ 06:09:44 starting module/cpyext/test/test_classobject.py [55 started in total]
__ module/cpyext/test/test_cell.py [52 done in total, somefailed=True] ________
[platform:msg] Updated environment with vsver 160, using x64 True
[platform:msg] Updated environment with vsver 160, using x64 True
============================= test session starts =============================
platform win32 -- Python 2.7.18[pypy-7.3.18-alpha], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('d:\\pypy_stuff\\buildbot64\\slave\\own-win-x86-64\\build\\pypy\\.hypothesis\\examples')
pytest-2.9.2 from d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pytest.pyc
rootdir: d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 1 items
module\cpyext\test\test_cell.py E
=================================== ERRORS ====================================
________________ ERROR at setup of AppTestCell.test_cell_type _________________
self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'>
func = <function <lambda> at 0x0000012d451935b0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000012d3cf41440>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000012d44650720>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000012d3d408660>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000012d3d4086a0>]
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 0x0000012d44650720>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000012d3d408660>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000012d3d4086a0>]
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 0x0000012d43d4fbc8>
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 0x0000012d43cba860>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000012d43cba860>
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 0x0000012d43ede1a8>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000012d43ede1a8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000012d43ede1a8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000012d43ede1a8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000012d443658a0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000012d44bfda98>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe499930a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49993060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49992ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000012d40516d40>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x0000012d43ede720>, <W_TypeObject 'GenericAlias' at 0x12d440dfb78>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x12d453c1cc8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x12d453c1cc8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x12d453c1cc8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x12d453c1cc8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x12d4108f210>>
w_obj = <W_TypeObject 'ellipsis' at 0x12d453c1cc8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x12d453c1cc8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x12d4108f210>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x12d453c1cc8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x12d4108f210>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x12d4108f210>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x12d4108f210>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E 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 44.06 seconds ===========================
++ 06:10:42 starting module/cpyext/test/test_codecs.py [56 started in total]
__ module/cpyext/test/test_classobject.py [53 done in total, somefailed=True] _
[platform:msg] Updated environment with vsver 160, using x64 True
[platform:msg] Updated environment with vsver 160, using x64 True
============================= test session starts =============================
platform win32 -- Python 2.7.18[pypy-7.3.18-alpha], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('d:\\pypy_stuff\\buildbot64\\slave\\own-win-x86-64\\build\\pypy\\.hypothesis\\examples')
pytest-2.9.2 from d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pytest.pyc
rootdir: d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 2 items
module\cpyext\test\test_classobject.py EE
=================================== ERRORS ====================================
_________ ERROR at setup of AppTestInstanceMethod.test_instancemethod _________
self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'>
func = <function <lambda> at 0x00000145143d6ae8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x000001450ddd33d0>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000014515a19f20>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001450e2946a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001450e2946e0>]
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 0x0000014515a19f20>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001450e2946a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001450e2946e0>]
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 0x0000014514b7c2c8>
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 0x000001451512ab20>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001451512ab20>
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 0x0000014514bd12b8>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000014514bd12b8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000014514bd12b8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000014514bd12b8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00000145143d0f60>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000014514a9a4b8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe499930a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49993060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49992ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000014513112b10>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x0000014514bd1868>, <W_TypeObject 'GenericAlias' at 0x14514bef130>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x145163b2330>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x145163b2330>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x145163b2330>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x145163b2330>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x145116b77a0>>
w_obj = <W_TypeObject 'ellipsis' at 0x145163b2330>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x145163b2330>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x145116b77a0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x145163b2330>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x145116b77a0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x145116b77a0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x145116b77a0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00000145192cc200>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x000001450ddd33d0>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000014515a19f20>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001450e2946a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001450e2946e0>]
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 0x0000014515a19f20>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001450e2946a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001450e2946e0>]
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 0x000001451935e930>
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 0x0000014519370020>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000014519370020>
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 0x0000014519362368>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000014519362368>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000014519362368>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000014519362368>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000001451979cee0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00000145197e7280>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe499530a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49953060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49952ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000014513112b10>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x0000014519362ad8>, <W_TypeObject 'GenericAlias' at 0x145128a84b8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x14514d41018>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x14514d41018>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x14514d41018>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x14514d41018>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x145116b8970>>
w_obj = <W_TypeObject 'ellipsis' at 0x14514d41018>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x14514d41018>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x145116b8970>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x14514d41018>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x145116b8970>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x145116b8970>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x145116b8970>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E 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 78.08 seconds ===========================
++ 06:11:42 starting module/cpyext/test/test_complexobject.py [57 started in total]
__ module/cpyext/test/test_codecs.py [54 done in total, somefailed=True] ______
[platform:msg] Updated environment with vsver 160, using x64 True
[platform:msg] Updated environment with vsver 160, using x64 True
============================= test session starts =============================
platform win32 -- Python 2.7.18[pypy-7.3.18-alpha], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('d:\\pypy_stuff\\buildbot64\\slave\\own-win-x86-64\\build\\pypy\\.hypothesis\\examples')
pytest-2.9.2 from d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pytest.pyc
rootdir: d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 3 items
module\cpyext\test\test_codecs.py EEE
=================================== ERRORS ====================================
________________ ERROR at setup of TestCodecs.test_incremental ________________
item = <Function 'test_incremental'>
@pytest.hookimpl(tryfirst=True)
def pytest_runtest_setup(item):
if isinstance(item, pytest.Function):
config = item.config
if get_marker(item, name='pypy_only'):
if config.applevel is not None and not config.applevel.is_pypy:
pytest.skip('PyPy-specific test')
appclass = item.getparent(pytest.Class)
if appclass is not None:
from pypy.tool.pytest.objspace import gettestobjspace
# Make cls.space and cls.runappdirect available in tests.
spaceconfig = getattr(appclass.obj, 'spaceconfig', {})
> appclass.obj.space = gettestobjspace(**spaceconfig)
conftest.py:259:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
tool\pytest\objspace.py:24: in gettestobjspace
space = maketestobjspace(config)
tool\pytest\objspace.py:34: in maketestobjspace
space = make_objspace(config)
tool\option.py:33: in make_objspace
return StdObjSpace(config)
interpreter\baseobjspace.py:481: in __init__
self.initialize()
objspace\std\objspace.py:118: in initialize
self.setup_builtin_modules()
interpreter\baseobjspace.py:739: in setup_builtin_modules
self.fromcache(State).build_api()
module\cpyext\state.py:128: in build_api
self.api_lib = str(api.build_bridge(self.space))
module\cpyext\api.py:1468: in build_bridge
builder.attach_all(space)
module\cpyext\api.py:1535: in attach_all
attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1497: in attach_recursively
make_ref(space, w_type))
module\cpyext\pyobject.py:510: in make_ref
return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:483: in get_pyobj_and_incref
pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445: in as_pyobj
py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:326: in create_ref
track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:375: in track_reference
w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:132: in _cpyext_attach_pyobj
rawrefcount.create_link_pypy(self, py_obj)
..\rpython\rlib\rawrefcount.py:187: in create_link_pypy
assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:102: in _ob_link_get
return ob.c_ob_pypy_link
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x228cce6bbc0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x228cce69f40>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00000228cf9f4a70>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00000228c7761440>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000228cf644120>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000228c7c266a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000228c7c266e0>]
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 0x00000228cf644120>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000228c7c266a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000228c7c266e0>]
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 0x00000228d1b00458>
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 0x00000228d173bb60>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000228d173bb60>
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 0x00000228d2514c60>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00000228d2514c60>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00000228d2514c60>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00000228d2514c60>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00000228d21a8620>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00000228d2b92560>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe499940a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49994060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49993ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00000228ccb4ca68>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x00000228d25151d8>, <W_TypeObject 'GenericAlias' at 0x228cd9d9670>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x228cd56fd38>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x228cd56fd38>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x228cd56fd38>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x228cd56fd38>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x228cce6a660>>
w_obj = <W_TypeObject 'ellipsis' at 0x228cd56fd38>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x228cd56fd38>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x228cce6a660>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x228cd56fd38>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x228cce6a660>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x228cce6a660>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x228cce6a660>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E 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 112.12 seconds ==========================
++ 06:13:16 starting module/cpyext/test/test_contextvars.py [58 started in total]
__ module/cpyext/test/test_contextvars.py [55 done in total, somefailed=True] _
[platform:msg] Updated environment with vsver 160, using x64 True
[platform:msg] Updated environment with vsver 160, using x64 True
============================= test session starts =============================
platform win32 -- Python 2.7.18[pypy-7.3.18-alpha], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('d:\\pypy_stuff\\buildbot64\\slave\\own-win-x86-64\\build\\pypy\\.hypothesis\\examples')
pytest-2.9.2 from d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pytest.pyc
rootdir: d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 1 items
module\cpyext\test\test_contextvars.py E
=================================== ERRORS ====================================
________________ ERROR at setup of AppTestContext.test_context ________________
self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'>
func = <function <lambda> at 0x0000024156bfc110>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x000002414f853408>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000024157afcca0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000002414fd166a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000002414fd166e0>]
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 0x0000024157afcca0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000002414fd166a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000002414fd166e0>]
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 0x0000024155d80980>
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 0x00000241570ed4e0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000241570ed4e0>
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 0x0000024156579ad0>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000024156579ad0>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000024156579ad0>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000024156579ad0>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000024156c98d20>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000002415744a678>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe499540a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49954060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49953ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00000241543d3c58>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x0000024156564598>, <W_TypeObject 'GenericAlias' at 0x24156a657c0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x24157d036e0>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x24157d036e0>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x24157d036e0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x24157d036e0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x241531b13c0>>
w_obj = <W_TypeObject 'ellipsis' at 0x24157d036e0>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x24157d036e0>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x241531b13c0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x24157d036e0>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x241531b13c0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x241531b13c0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x241531b13c0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E 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 43.09 seconds ===========================
++ 06:14:37 starting module/cpyext/test/test_cpyext.py [59 started in total]
__ module/cpyext/test/test_complexobject.py [56 done in total, somefailed=True]
[platform:msg] Updated environment with vsver 160, using x64 True
[platform:msg] Updated environment with vsver 160, using x64 True
============================= test session starts =============================
platform win32 -- Python 2.7.18[pypy-7.3.18-alpha], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('d:\\pypy_stuff\\buildbot64\\slave\\own-win-x86-64\\build\\pypy\\.hypothesis\\examples')
pytest-2.9.2 from d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pytest.pyc
rootdir: d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 6 items
module\cpyext\test\test_complexobject.py EEEEEE
=================================== ERRORS ====================================
___________ ERROR at setup of TestComplexObject.test_complexobject ____________
item = <Function 'test_complexobject'>
@pytest.hookimpl(tryfirst=True)
def pytest_runtest_setup(item):
if isinstance(item, pytest.Function):
config = item.config
if get_marker(item, name='pypy_only'):
if config.applevel is not None and not config.applevel.is_pypy:
pytest.skip('PyPy-specific test')
appclass = item.getparent(pytest.Class)
if appclass is not None:
from pypy.tool.pytest.objspace import gettestobjspace
# Make cls.space and cls.runappdirect available in tests.
spaceconfig = getattr(appclass.obj, 'spaceconfig', {})
> appclass.obj.space = gettestobjspace(**spaceconfig)
conftest.py:259:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
tool\pytest\objspace.py:24: in gettestobjspace
space = maketestobjspace(config)
tool\pytest\objspace.py:34: in maketestobjspace
space = make_objspace(config)
tool\option.py:33: in make_objspace
return StdObjSpace(config)
interpreter\baseobjspace.py:481: in __init__
self.initialize()
objspace\std\objspace.py:118: in initialize
self.setup_builtin_modules()
interpreter\baseobjspace.py:739: in setup_builtin_modules
self.fromcache(State).build_api()
module\cpyext\state.py:128: in build_api
self.api_lib = str(api.build_bridge(self.space))
module\cpyext\api.py:1468: in build_bridge
builder.attach_all(space)
module\cpyext\api.py:1535: in attach_all
attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1497: in attach_recursively
make_ref(space, w_type))
module\cpyext\pyobject.py:510: in make_ref
return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:483: in get_pyobj_and_incref
pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445: in as_pyobj
py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:326: in create_ref
track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:375: in track_reference
w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:132: in _cpyext_attach_pyobj
rawrefcount.create_link_pypy(self, py_obj)
..\rpython\rlib\rawrefcount.py:187: in create_link_pypy
assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:102: in _ob_link_get
return ob.c_ob_pypy_link
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x183b251b0d0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00000183b7f98200>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00000183aced3398>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000183b54f6060>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000183ad394660>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000183ad3946a0>]
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 0x00000183b54f6060>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000183ad394660>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000183ad3946a0>]
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 0x00000183b7fe5ad8>
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 0x00000183b7f3dd20>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000183b7f3dd20>
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 0x00000183b7fd16a8>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00000183b7fd16a8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00000183b7fd16a8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00000183b7fd16a8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00000183b82eeb60>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00000183b46b82f8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe499940a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49994060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49993ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00000183b1887d70>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x00000183b7fd1c20>, <W_TypeObject 'GenericAlias' at 0x183b306c9f8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x183b3cd5bb0>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x183b3cd5bb0>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x183b3cd5bb0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x183b3cd5bb0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x183b251d800>>
w_obj = <W_TypeObject 'ellipsis' at 0x183b3cd5bb0>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x183b3cd5bb0>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x183b251d800>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x183b3cd5bb0>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x183b251d800>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x183b251d800>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x183b251d800>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00000183b3f88908>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00000183aced3398>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000183b54f6060>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000183ad394660>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000183ad3946a0>]
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 0x00000183b54f6060>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000183ad394660>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000183ad3946a0>]
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 0x00000183b62e9a60>
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 0x00000183b7875160>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000183b7875160>
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 0x00000183b7837b08>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00000183b7837b08>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00000183b7837b08>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00000183b7837b08>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00000183b79c0e20>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00000183b3ef60c8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe499540a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49954060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49953ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00000183b1887d70>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x00000183b787e0c8>, <W_TypeObject 'GenericAlias' at 0x183b2eca800>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x183b29ee838>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x183b29ee838>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x183b29ee838>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x183b29ee838>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x183b251cd50>>
w_obj = <W_TypeObject 'ellipsis' at 0x183b29ee838>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x183b29ee838>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x183b251cd50>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x183b29ee838>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x183b251cd50>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x183b251cd50>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x183b251cd50>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00000183b843d448>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00000183aced3398>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000183b54f6060>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000183ad394660>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000183ad3946a0>]
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 0x00000183b54f6060>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000183ad394660>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000183ad3946a0>]
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 0x00000183b0567d08>
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 0x00000183b7140220>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000183b7140220>
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 0x00000183b6119cc8>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00000183b6119cc8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00000183b6119cc8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00000183b6119cc8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00000183b41ca860>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00000183b2d15088>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe499940a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49994060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49993ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00000183b1887d70>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x00000183b7148288>, <W_TypeObject 'GenericAlias' at 0x183b35c0560>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x183b306c4f0>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x183b306c4f0>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x183b306c4f0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x183b306c4f0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x183b251b7f0>>
w_obj = <W_TypeObject 'ellipsis' at 0x183b306c4f0>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x183b306c4f0>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x183b251b7f0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x183b306c4f0>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x183b251b7f0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x183b251b7f0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x183b251b7f0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00000183b58b7448>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00000183aced3398>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000183b54f6060>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000183ad394660>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000183ad3946a0>]
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 0x00000183b54f6060>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000183ad394660>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000183ad3946a0>]
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 0x00000183b33c41d8>
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 0x00000183b5acea20>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000183b5acea20>
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 0x00000183b5b09f30>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00000183b5b09f30>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00000183b5b09f30>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00000183b5b09f30>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00000183b5acfc20>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00000183b334a100>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe499940a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49994060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49993ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00000183b1887d70>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x00000183b7c9c838>, <W_TypeObject 'GenericAlias' at 0x183b396b750>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x183b362afe0>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x183b362afe0>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x183b362afe0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x183b362afe0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x183b251d0e0>>
w_obj = <W_TypeObject 'ellipsis' at 0x183b362afe0>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x183b362afe0>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x183b251d0e0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x183b362afe0>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x183b251d0e0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x183b251d0e0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x183b251d0e0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00000183b51951f0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00000183aced3398>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000183b54f6060>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000183ad394660>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000183ad3946a0>]
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 0x00000183b54f6060>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000183ad394660>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000183ad3946a0>]
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 0x00000183b42df808>
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 0x00000183b5c62820>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000183b5c62820>
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 0x00000183b5c60720>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00000183b5c60720>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00000183b5c60720>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00000183b5c60720>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00000183b5a3a720>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00000183b2d3cde8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe498e40a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe498e4060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe498e3ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00000183b1887d70>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x00000183b5c60c98>, <W_TypeObject 'GenericAlias' at 0x183b43341e0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x183b3aa9ef8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x183b3aa9ef8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x183b3aa9ef8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x183b3aa9ef8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x183b251d470>>
w_obj = <W_TypeObject 'ellipsis' at 0x183b3aa9ef8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x183b3aa9ef8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x183b251d470>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x183b3aa9ef8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x183b251d470>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x183b251d470>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x183b251d470>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E 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 214.86 seconds ==========================
++ 06:15:57 starting module/cpyext/test/test_datetime.py [60 started in total]
__ module/cpyext/test/test_bytesobject.py [57 done in total, somefailed=True] _
[platform:msg] Updated environment with vsver 160, using x64 True
[platform:msg] Updated environment with vsver 160, using x64 True
============================= test session starts =============================
platform win32 -- Python 2.7.18[pypy-7.3.18-alpha], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('d:\\pypy_stuff\\buildbot64\\slave\\own-win-x86-64\\build\\pypy\\.hypothesis\\examples')
pytest-2.9.2 from d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pytest.pyc
rootdir: d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 20 items
module\cpyext\test\test_bytesobject.py EEEEEEEEEEEEEEEEEEEE
=================================== ERRORS ====================================
____________ ERROR at setup of AppTestBytesObject.test_bytesobject ____________
self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'>
func = <function <lambda> at 0x0000021d701c0c50>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000021d68961440>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000021d6e8b2b20>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000021d68e266a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000021d68e266e0>]
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 0x0000021d6e8b2b20>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000021d68e266a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000021d68e266e0>]
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 0x0000021d6f86f880>
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 0x0000021d7060fba0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000021d7060fba0>
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 0x0000021d6f732138>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000021d6f732138>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000021d6f732138>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000021d6f732138>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000021d6ea47820>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000021d6fce3de0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe498f40a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe498f4060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe498f3ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000021d6d2fbbb0>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x0000021d6f732838>, <W_TypeObject 'GenericAlias' at 0x21d6e8c3638>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x21d7192ac28>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x21d7192ac28>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x21d7192ac28>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x21d7192ac28>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x21d6e31b6c0>>
w_obj = <W_TypeObject 'ellipsis' at 0x21d7192ac28>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x21d7192ac28>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x21d6e31b6c0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x21d7192ac28>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x21d6e31b6c0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x21d6e31b6c0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x21d6e31b6c0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x0000021d736e7100>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000021d68961440>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000021d6e8b2b20>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000021d68e266a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000021d68e266e0>]
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 0x0000021d6e8b2b20>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000021d68e266a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000021d68e266e0>]
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 0x0000021d73e96908>
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 0x0000021d73e86de0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000021d73e86de0>
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 0x0000021d73e921e0>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000021d73e921e0>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000021d73e921e0>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000021d73e921e0>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000021d741940e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000021d70b0abf0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe498b40a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe498b4060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe498b3ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000021d6d2fbbb0>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x0000021d73e92758>, <W_TypeObject 'GenericAlias' at 0x21d6e254c98>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x21d6f5b6e90>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x21d6f5b6e90>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x21d6f5b6e90>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x21d6f5b6e90>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x21d6e31b330>>
w_obj = <W_TypeObject 'ellipsis' at 0x21d6f5b6e90>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x21d6f5b6e90>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x21d6e31b330>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x21d6f5b6e90>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x21d6e31b330>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x21d6e31b330>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x21d6e31b330>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x0000021d701f1970>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000021d68961440>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000021d6e8b2b20>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000021d68e266a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000021d68e266e0>]
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 0x0000021d6e8b2b20>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000021d68e266a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000021d68e266e0>]
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 0x0000021d73143808>
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 0x0000021d73917760>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000021d73917760>
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 0x0000021d7394f788>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000021d7394f788>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000021d7394f788>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000021d7394f788>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000021d71f608e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000021d6fdede50>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe498f40a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe498f4060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe498f3ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000021d6d2fbbb0>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x0000021d7394fd00>, <W_TypeObject 'GenericAlias' at 0x21d6eca2100>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x21d6e8e4e58>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x21d6e8e4e58>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x21d6e8e4e58>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x21d6e8e4e58>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x21d6e31ba50>>
w_obj = <W_TypeObject 'ellipsis' at 0x21d6e8e4e58>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x21d6e8e4e58>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x21d6e31ba50>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x21d6e8e4e58>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x21d6e31ba50>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x21d6e31ba50>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x21d6e31ba50>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x0000021d6f593d30>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000021d68961440>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000021d6e8b2b20>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000021d68e266a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000021d68e266e0>]
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 0x0000021d6e8b2b20>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000021d68e266a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000021d68e266e0>]
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 0x0000021d6ee06200>
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 0x0000021d72cf1660>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000021d72cf1660>
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 0x0000021d72c8e170>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000021d72c8e170>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000021d72c8e170>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000021d72c8e170>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000021d73bf2860>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000021d6f7ccd08>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe498b40a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe498b4060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe498b3ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000021d6d2fbbb0>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x0000021d72c8e6e8>, <W_TypeObject 'GenericAlias' at 0x21d6fbfac28>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x21d6f0a5d38>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x21d6f0a5d38>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x21d6f0a5d38>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x21d6f0a5d38>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x21d6e31e510>>
w_obj = <W_TypeObject 'ellipsis' at 0x21d6f0a5d38>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x21d6f0a5d38>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x21d6e31e510>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x21d6f0a5d38>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x21d6e31e510>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x21d6e31e510>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x21d6e31e510>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x0000021d6d964f98>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000021d68961440>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000021d6e8b2b20>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000021d68e266a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000021d68e266e0>]
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 0x0000021d6e8b2b20>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000021d68e266a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000021d68e266e0>]
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 0x0000021d6f109920>
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 0x0000021d72f523a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000021d72f523a0>
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 0x0000021d72e634b0>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000021d72e634b0>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000021d72e634b0>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000021d72e634b0>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000021d739bb320>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000021d6eb6bb08>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe499940a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49994060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49993ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000021d6d2fbbb0>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x0000021d72e63a28>, <W_TypeObject 'GenericAlias' at 0x21d6fe0a138>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x21d6f07e138>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x21d6f07e138>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x21d6f07e138>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x21d6f07e138>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x21d6e31cfb0>>
w_obj = <W_TypeObject 'ellipsis' at 0x21d6f07e138>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x21d6f07e138>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x21d6e31cfb0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x21d6f07e138>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x21d6e31cfb0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x21d6e31cfb0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x21d6e31cfb0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x0000021d6f656980>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000021d68961440>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000021d6e8b2b20>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000021d68e266a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000021d68e266e0>]
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 0x0000021d6e8b2b20>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000021d68e266a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000021d68e266e0>]
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 0x0000021d71de2e08>
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 0x0000021d738f5420>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000021d738f5420>
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 0x0000021d738ffe18>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000021d738ffe18>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000021d738ffe18>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000021d738ffe18>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000021d7276c4e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000021d6bc36448>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe499540a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49954060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49953ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000021d6d2fbbb0>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x0000021d736c46e8>, <W_TypeObject 'GenericAlias' at 0x21d6fce0e58>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x21d6f2d0ad8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x21d6f2d0ad8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x21d6f2d0ad8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x21d6f2d0ad8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x21d6e31ddf0>>
w_obj = <W_TypeObject 'ellipsis' at 0x21d6f2d0ad8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x21d6f2d0ad8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x21d6e31ddf0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x21d6f2d0ad8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x21d6e31ddf0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x21d6e31ddf0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x21d6e31ddf0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x0000021d74211e20>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000021d68961440>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000021d6e8b2b20>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000021d68e266a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000021d68e266e0>]
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 0x0000021d6e8b2b20>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000021d68e266a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000021d68e266e0>]
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 0x0000021d6fca33d0>
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 0x0000021d735e0aa0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000021d735e0aa0>
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 0x0000021d72475980>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000021d72475980>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000021d72475980>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000021d72475980>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000021d735e1d60>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000021d6fc7da28>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe498a40a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe498a4060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe498a3ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000021d6d2fbbb0>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x0000021d72475ef8>, <W_TypeObject 'GenericAlias' at 0x21d6ffa8838>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x21d6fd40d08>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x21d6fd40d08>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x21d6fd40d08>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x21d6fd40d08>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x21d6e31c890>>
w_obj = <W_TypeObject 'ellipsis' at 0x21d6fd40d08>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x21d6fd40d08>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x21d6e31c890>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x21d6fd40d08>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x21d6e31c890>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x21d6e31c890>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x21d6e31c890>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x0000021d73111808>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000021d68961440>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000021d6e8b2b20>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000021d68e266a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000021d68e266e0>]
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 0x0000021d6e8b2b20>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000021d68e266a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000021d68e266e0>]
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 0x0000021d6d4d2c78>
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 0x0000021d72662ee0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000021d72662ee0>
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 0x0000021d7269c9c0>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000021d7269c9c0>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000021d7269c9c0>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000021d7269c9c0>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000021d723b4120>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000021d6fb00448>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe499940a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49994060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49993ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000021d6d2fbbb0>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x0000021d7269cf38>, <W_TypeObject 'GenericAlias' at 0x21d6ffc8838>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x21d6fbfba28>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x21d6fbfba28>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x21d6fbfba28>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x21d6fbfba28>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x21d6e31da60>>
w_obj = <W_TypeObject 'ellipsis' at 0x21d6fbfba28>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x21d6fbfba28>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x21d6e31da60>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x21d6fbfba28>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x21d6e31da60>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x21d6e31da60>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x21d6e31da60>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x0000021d701c9718>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000021d68961440>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000021d6e8b2b20>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000021d68e266a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000021d68e266e0>]
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 0x0000021d6e8b2b20>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000021d68e266a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000021d68e266e0>]
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 0x0000021d6f290890>
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 0x0000021d72691de0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000021d72691de0>
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 0x0000021d72697600>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000021d72697600>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000021d72697600>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000021d72697600>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000021d72092f60>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000021d6fb00218>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe499540a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49954060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49953ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000021d6d2fbbb0>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x0000021d72091590>, <W_TypeObject 'GenericAlias' at 0x21d7002d248>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x21d6fe26b10>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x21d6fe26b10>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x21d6fe26b10>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x21d6fe26b10>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x21d6e31d340>>
w_obj = <W_TypeObject 'ellipsis' at 0x21d6fe26b10>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x21d6fe26b10>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x21d6e31d340>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x21d6fe26b10>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x21d6e31d340>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x21d6e31d340>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x21d6e31d340>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x21d6e31e180>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x21d6bab5570>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x21d6bab4730>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x21d6bab43a0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x21d6e31ec30>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x21d6b015a10>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x21d6b0152f0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x21d6b016850>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x21d6b014840>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x21d6b013d90>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x21d6b015da0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E 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 679.73 seconds ==========================
++ 06:19:17 starting module/cpyext/test/test_dictobject.py [61 started in total]
__ module/cpyext/test/test_datetime.py [58 done in total, somefailed=True] ____
[platform:msg] Updated environment with vsver 160, using x64 True
[platform:msg] Updated environment with vsver 160, using x64 True
============================= test session starts =============================
platform win32 -- Python 2.7.18[pypy-7.3.18-alpha], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('d:\\pypy_stuff\\buildbot64\\slave\\own-win-x86-64\\build\\pypy\\.hypothesis\\examples')
pytest-2.9.2 from d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pytest.pyc
rootdir: d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 16 items
module\cpyext\test\test_datetime.py EEEEEEEEEEEEEEEE
=================================== ERRORS ====================================
__________________ ERROR at setup of TestDatetime.test_date ___________________
item = <Function 'test_date'>
@pytest.hookimpl(tryfirst=True)
def pytest_runtest_setup(item):
if isinstance(item, pytest.Function):
config = item.config
if get_marker(item, name='pypy_only'):
if config.applevel is not None and not config.applevel.is_pypy:
pytest.skip('PyPy-specific test')
appclass = item.getparent(pytest.Class)
if appclass is not None:
from pypy.tool.pytest.objspace import gettestobjspace
# Make cls.space and cls.runappdirect available in tests.
spaceconfig = getattr(appclass.obj, 'spaceconfig', {})
> appclass.obj.space = gettestobjspace(**spaceconfig)
conftest.py:259:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
tool\pytest\objspace.py:24: in gettestobjspace
space = maketestobjspace(config)
tool\pytest\objspace.py:34: in maketestobjspace
space = make_objspace(config)
tool\option.py:33: in make_objspace
return StdObjSpace(config)
interpreter\baseobjspace.py:481: in __init__
self.initialize()
objspace\std\objspace.py:118: in initialize
self.setup_builtin_modules()
interpreter\baseobjspace.py:739: in setup_builtin_modules
self.fromcache(State).build_api()
module\cpyext\state.py:128: in build_api
self.api_lib = str(api.build_bridge(self.space))
module\cpyext\api.py:1468: in build_bridge
builder.attach_all(space)
module\cpyext\api.py:1535: in attach_all
attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1497: in attach_recursively
make_ref(space, w_type))
module\cpyext\pyobject.py:510: in make_ref
return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:483: in get_pyobj_and_incref
pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445: in as_pyobj
py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:326: in create_ref
track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:375: in track_reference
w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:132: in _cpyext_attach_pyobj
rawrefcount.create_link_pypy(self, py_obj)
..\rpython\rlib\rawrefcount.py:187: in create_link_pypy
assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:102: in _ob_link_get
return ob.c_ob_pypy_link
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1c1be3a8880>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x1c1be3a76b0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x1c1be3a6f90>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x1c1be3a7dd0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x1c1be3a7320>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x1c1be3a8160>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x1c1be3a96c0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x1c1be3a84f0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x1c1be3a7a40>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x000001c1c3cf9e20>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x000001c1b8cf1440>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001c1c0478160>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001c1b91b66a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001c1b91b66e0>]
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 0x000001c1c0478160>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001c1b91b66a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001c1b91b66e0>]
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 0x000001c1c2351718>
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 0x000001c1c2ba2860>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001c1c2ba2860>
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 0x000001c1c2bbcaa0>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001c1c2bbcaa0>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001c1c2bbcaa0>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000001c1c2bbcaa0>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000001c1c20181a0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000001c1be2f8138>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe499940a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49994060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49993ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000001c1bda60fe0>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x000001c1c2bbd018>, <W_TypeObject 'GenericAlias' at 0x1c1bfe6e528>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1c1bfb95ef8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1c1bfb95ef8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1c1bfb95ef8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1c1bfb95ef8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1c1be3a8c10>>
w_obj = <W_TypeObject 'ellipsis' at 0x1c1bfb95ef8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x1c1bfb95ef8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1c1be3a8c10>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x1c1bfb95ef8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1c1be3a8c10>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1c1be3a8c10>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1c1be3a8c10>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x000001c1c3d563e0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x000001c1b8cf1440>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001c1c0478160>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001c1b91b66a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001c1b91b66e0>]
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 0x000001c1c0478160>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001c1b91b66a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001c1b91b66e0>]
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 0x000001c1beec7470>
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 0x000001c1c23df760>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001c1c23df760>
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 0x000001c1c23f3c58>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001c1c23f3c58>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001c1c23f3c58>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000001c1c23f3c58>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000001c1c2f068e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000001c1bfae8790>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe499540a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49954060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49953ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000001c1bda60fe0>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x000001c1c32a6218>, <W_TypeObject 'GenericAlias' at 0x1c1bff88598>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1c1bf96c720>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1c1bf96c720>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1c1bf96c720>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1c1bf96c720>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1c1b8a45b10>>
w_obj = <W_TypeObject 'ellipsis' at 0x1c1bf96c720>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x1c1bf96c720>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1c1b8a45b10>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x1c1bf96c720>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1c1b8a45b10>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1c1b8a45b10>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1c1b8a45b10>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x000001c1bfb33e20>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x000001c1b8cf1440>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001c1c0478160>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001c1b91b66a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001c1b91b66e0>]
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 0x000001c1c0478160>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001c1b91b66a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001c1b91b66e0>]
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 0x000001c1bca1a250>
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 0x000001c1c296dfa0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001c1c296dfa0>
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 0x000001c1c24be9c0>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001c1c24be9c0>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001c1c24be9c0>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000001c1c24be9c0>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000001c1c249f2e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000001c1bd861ec0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe499540a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49954060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49953ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000001c1bda60fe0>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x000001c1c24bef38>, <W_TypeObject 'GenericAlias' at 0x1c1bff9c598>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1c1bfbdf5c8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1c1bfbdf5c8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1c1bfbdf5c8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1c1bfbdf5c8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1c1b8a46950>>
w_obj = <W_TypeObject 'ellipsis' at 0x1c1bfbdf5c8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x1c1bfbdf5c8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1c1b8a46950>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x1c1bfbdf5c8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1c1b8a46950>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1c1b8a46950>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1c1b8a46950>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x000001c1c39a1cb8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x000001c1b8cf1440>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001c1c0478160>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001c1b91b66a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001c1b91b66e0>]
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 0x000001c1c0478160>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001c1b91b66a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001c1b91b66e0>]
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 0x000001c1bf979768>
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 0x000001c1c21015a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001c1c21015a0>
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 0x000001c1c212d408>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001c1c212d408>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001c1c212d408>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000001c1c212d408>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000001c1c2988aa0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000001c1ba7e2e58>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe499540a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49954060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49953ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000001c1bda60fe0>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x000001c1c212d980>, <W_TypeObject 'GenericAlias' at 0x1c1bffa6fa8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1c1bfb95520>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1c1bfb95520>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1c1bfb95520>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1c1bfb95520>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1c1be3a9de0>>
w_obj = <W_TypeObject 'ellipsis' at 0x1c1bfb95520>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x1c1bfb95520>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1c1be3a9de0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x1c1bfb95520>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1c1be3a9de0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1c1be3a9de0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1c1be3a9de0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x000001c1c038c7a0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x000001c1b8cf1440>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001c1c0478160>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001c1b91b66a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001c1b91b66e0>]
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 0x000001c1c0478160>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001c1b91b66a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001c1b91b66e0>]
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 0x000001c1c2a98db8>
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 0x000001c1c367fca0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001c1c367fca0>
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 0x000001c1c290ef70>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001c1c290ef70>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001c1c290ef70>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000001c1c290ef70>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000001c1c2936fe0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000001c1c331ca68>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe499940a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49994060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49993ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000001c1bda60fe0>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x000001c1c290f4e8>, <W_TypeObject 'GenericAlias' at 0x1c1bffc4e20>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1c1bfc7b4e8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1c1bfc7b4e8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1c1bfc7b4e8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1c1bfc7b4e8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1c1ba638ba0>>
w_obj = <W_TypeObject 'ellipsis' at 0x1c1bfc7b4e8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x1c1bfc7b4e8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1c1ba638ba0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x1c1bfc7b4e8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1c1ba638ba0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1c1ba638ba0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1c1ba638ba0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x000001c1c3cf9010>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x000001c1b8cf1440>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001c1c0478160>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001c1b91b66a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001c1b91b66e0>]
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 0x000001c1c0478160>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001c1b91b66a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001c1b91b66e0>]
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 0x000001c1bf047128>
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 0x000001c1c340e5a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001c1c340e5a0>
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 0x000001c1c33db0f8>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001c1c33db0f8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001c1c33db0f8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000001c1c33db0f8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000001c1c340f760>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000001c1c2e1ede8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe499940a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49994060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49993ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000001c1bda60fe0>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x000001c1c33db670>, <W_TypeObject 'GenericAlias' at 0x1c1bff9cb80>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1c1bfbde6b0>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1c1bfbde6b0>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1c1bfbde6b0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1c1bfbde6b0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1c1ba63b660>>
w_obj = <W_TypeObject 'ellipsis' at 0x1c1bfbde6b0>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x1c1bfbde6b0>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1c1ba63b660>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x1c1bfbde6b0>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1c1ba63b660>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1c1ba63b660>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1c1ba63b660>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x000001c1c10b06b0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x000001c1b8cf1440>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001c1c0478160>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001c1b91b66a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001c1b91b66e0>]
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 0x000001c1c0478160>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001c1b91b66a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001c1b91b66e0>]
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 0x000001c1c0bbc0e8>
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 0x000001c1c202a760>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001c1c202a760>
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 0x000001c1c202f718>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001c1c202f718>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001c1c202f718>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000001c1c202f718>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000001c1c202b7a0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000001c1c322cdb0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe499540a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49954060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49953ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000001c1bda60fe0>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x000001c1c202fc90>, <W_TypeObject 'GenericAlias' at 0x1c1bffc4090>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1c1bfda3980>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1c1bfda3980>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1c1bfda3980>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1c1bfda3980>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1c1ba637d60>>
w_obj = <W_TypeObject 'ellipsis' at 0x1c1bfda3980>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x1c1bfda3980>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1c1ba637d60>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x1c1bfda3980>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1c1ba637d60>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1c1ba637d60>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1c1ba637d60>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E 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 548.85 seconds ==========================
++ 06:25:45 starting module/cpyext/test/test_eval.py [62 started in total]
__ module/cpyext/test/test_cpyext.py [59 done in total, somefailed=True] ______
[platform:msg] Updated environment with vsver 160, using x64 True
[platform:msg] Updated environment with vsver 160, using x64 True
============================= test session starts =============================
platform win32 -- Python 2.7.18[pypy-7.3.18-alpha], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('d:\\pypy_stuff\\buildbot64\\slave\\own-win-x86-64\\build\\pypy\\.hypothesis\\examples')
pytest-2.9.2 from d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pytest.pyc
rootdir: d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 26 items
module\cpyext\test\test_cpyext.py .EEEEEEEEEEEEEEEEEEEEEEEEE
=================================== ERRORS ====================================
________________ ERROR at setup of AppTestApi.test_only_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 0x000001d32e634278>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=item, **kwds), when=when)
..\_pytest\runner.py:138:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_HookCaller 'pytest_runtest_setup'>
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_only_import'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_only_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 0x000001d327531440>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d32f2fcd60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001d3279f86a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d3279f86e0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_only_import'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_only_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 0x000001d32f2fcd60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001d3279f86a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d3279f86e0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_only_import'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_only_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_only_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 0x000001d32d76f510>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...nly_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 0x000001d32d4f8920>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001d32d4f8920>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...nly_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_only_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_only_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 0x000001d32dff7bb0>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001d32dff7bb0>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001d32dff7bb0>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000001d32dff7bb0>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000001d32d65b5e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000001d32ed02608>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe499930a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49993060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49992ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000001d32c0def38>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x000001d32dfd97c0>, <W_TypeObject 'GenericAlias' at 0x1d32d9eef38>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32f9391d8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32f9391d8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32f9391d8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32f9391d8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32cb46fc0>>
w_obj = <W_TypeObject 'ellipsis' at 0x1d32f9391d8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x1d32f9391d8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32cb46fc0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x1d32f9391d8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32cb46fc0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32cb46fc0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32cb46fc0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'
..\rpython\rtyper\lltypesystem\lltype.py:1270: AttributeError
_________________ ERROR at setup of AppTestApi.test_dllhandle _________________
self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'>
func = <function <lambda> at 0x000001d332370c50>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=item, **kwds), when=when)
..\_pytest\runner.py:138:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_HookCaller 'pytest_runtest_setup'>
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_dllhandle'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_dllhandle'>}
def __call__(self, **kwargs):
assert not self.is_historic()
> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
..\_pytest\vendored_packages\pluggy.py:724:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.config.PytestPluginManager object at 0x000001d327531440>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d32f2fcd60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001d3279f86a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d3279f86e0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_dllhandle'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_dllhandle'>}
def _hookexec(self, hook, methods, kwargs):
# called from all hookcaller instances.
# enable_tracing will set its own wrapping function at self._inner_hookexec
> return self._inner_hookexec(hook, methods, kwargs)
..\_pytest\vendored_packages\pluggy.py:338:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d32f2fcd60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001d3279f86a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d3279f86e0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_dllhandle'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_dllhandle'>}
self._inner_hookexec = lambda hook, methods, kwargs: \
> _MultiCall(methods, kwargs, hook.spec_opts).execute()
..\_pytest\vendored_packages\pluggy.py:333:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_dllhandle'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
> return _wrapped_call(hook_impl.function(*args), self.execute)
..\_pytest\vendored_packages\pluggy.py:595:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
wrap_controller = <generator object pytest_runtest_setup at 0x000001d33244b290>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i..._dllhandle'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>>
def _wrapped_call(wrap_controller, func):
""" Wrap calling to a function with a generator which needs to yield
exactly once. The yield point will trigger calling the wrapped function
and return its _CallOutcome to the yield point. The generator then needs
to finish (raise StopIteration) in order for the wrapped call to complete.
"""
try:
next(wrap_controller) # first yield
except StopIteration:
_raise_wrapfail(wrap_controller, "did not yield")
call_outcome = _CallOutcome(func)
try:
wrap_controller.send(call_outcome)
_raise_wrapfail(wrap_controller, "has second yield")
except StopIteration:
pass
> return call_outcome.get_result()
..\_pytest\vendored_packages\pluggy.py:253:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001d3323cd660>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001d3323cd660>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i..._dllhandle'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>>
def __init__(self, func):
try:
> self.result = func()
..\_pytest\vendored_packages\pluggy.py:264:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_dllhandle'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
return _wrapped_call(hook_impl.function(*args), self.execute)
> res = hook_impl.function(*args)
..\_pytest\vendored_packages\pluggy.py:596:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
item = <AppTestMethod 'test_dllhandle'>
@pytest.hookimpl(tryfirst=True)
def pytest_runtest_setup(item):
if isinstance(item, pytest.Function):
config = item.config
if get_marker(item, name='pypy_only'):
if config.applevel is not None and not config.applevel.is_pypy:
pytest.skip('PyPy-specific test')
appclass = item.getparent(pytest.Class)
if appclass is not None:
from pypy.tool.pytest.objspace import gettestobjspace
# Make cls.space and cls.runappdirect available in tests.
spaceconfig = getattr(appclass.obj, 'spaceconfig', {})
> appclass.obj.space = gettestobjspace(**spaceconfig)
conftest.py:259:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]}
config = <rpython.config.config.Config object at 0x000001d3324458d8>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001d3324458d8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001d3324458d8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000001d3324458d8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000001d3327435a0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000001d32ed0fde0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe499930a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49993060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49992ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000001d32c0def38>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x000001d332495248>, <W_TypeObject 'GenericAlias' at 0x1d328565440>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32df74ec8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32df74ec8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32df74ec8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32df74ec8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32cb48520>>
w_obj = <W_TypeObject 'ellipsis' at 0x1d32df74ec8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x1d32df74ec8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32cb48520>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x1d32df74ec8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32cb48520>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32cb48520>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32cb48520>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'
..\rpython\rtyper\lltypesystem\lltype.py:1270: AttributeError
_________ ERROR at setup of AppTestCpythonExtension.test_createmodule _________
self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'>
func = <function <lambda> at 0x000001d32e8d54c0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=item, **kwds), when=when)
..\_pytest\runner.py:138:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_HookCaller 'pytest_runtest_setup'>
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_createmodule'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_createmodule'>}
def __call__(self, **kwargs):
assert not self.is_historic()
> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
..\_pytest\vendored_packages\pluggy.py:724:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.config.PytestPluginManager object at 0x000001d327531440>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d32f2fcd60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001d3279f86a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d3279f86e0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_createmodule'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_createmodule'>}
def _hookexec(self, hook, methods, kwargs):
# called from all hookcaller instances.
# enable_tracing will set its own wrapping function at self._inner_hookexec
> return self._inner_hookexec(hook, methods, kwargs)
..\_pytest\vendored_packages\pluggy.py:338:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d32f2fcd60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001d3279f86a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d3279f86e0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_createmodule'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_createmodule'>}
self._inner_hookexec = lambda hook, methods, kwargs: \
> _MultiCall(methods, kwargs, hook.spec_opts).execute()
..\_pytest\vendored_packages\pluggy.py:333:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_createmodule'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
> return _wrapped_call(hook_impl.function(*args), self.execute)
..\_pytest\vendored_packages\pluggy.py:595:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
wrap_controller = <generator object pytest_runtest_setup at 0x000001d33101cae8>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...eatemodule'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>>
def _wrapped_call(wrap_controller, func):
""" Wrap calling to a function with a generator which needs to yield
exactly once. The yield point will trigger calling the wrapped function
and return its _CallOutcome to the yield point. The generator then needs
to finish (raise StopIteration) in order for the wrapped call to complete.
"""
try:
next(wrap_controller) # first yield
except StopIteration:
_raise_wrapfail(wrap_controller, "did not yield")
call_outcome = _CallOutcome(func)
try:
wrap_controller.send(call_outcome)
_raise_wrapfail(wrap_controller, "has second yield")
except StopIteration:
pass
> return call_outcome.get_result()
..\_pytest\vendored_packages\pluggy.py:253:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001d330b63e20>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001d330b63e20>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...eatemodule'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>>
def __init__(self, func):
try:
> self.result = func()
..\_pytest\vendored_packages\pluggy.py:264:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_createmodule'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
return _wrapped_call(hook_impl.function(*args), self.execute)
> res = hook_impl.function(*args)
..\_pytest\vendored_packages\pluggy.py:596:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
item = <AppTestMethod 'test_createmodule'>
@pytest.hookimpl(tryfirst=True)
def pytest_runtest_setup(item):
if isinstance(item, pytest.Function):
config = item.config
if get_marker(item, name='pypy_only'):
if config.applevel is not None and not config.applevel.is_pypy:
pytest.skip('PyPy-specific test')
appclass = item.getparent(pytest.Class)
if appclass is not None:
from pypy.tool.pytest.objspace import gettestobjspace
# Make cls.space and cls.runappdirect available in tests.
spaceconfig = getattr(appclass.obj, 'spaceconfig', {})
> appclass.obj.space = gettestobjspace(**spaceconfig)
conftest.py:259:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]}
config = <rpython.config.config.Config object at 0x000001d330636a30>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001d330636a30>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001d330636a30>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000001d330636a30>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000001d3313adfa0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000001d32ecee250>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe499530a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49953060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49952ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000001d32c0def38>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x000001d3309beaa0>, <W_TypeObject 'GenericAlias' at 0x1d32d65fef8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32df358d8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32df358d8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32df358d8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32df358d8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32cb48c40>>
w_obj = <W_TypeObject 'ellipsis' at 0x1d32df358d8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x1d32df358d8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32cb48c40>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x1d32df358d8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32cb48c40>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32cb48c40>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32cb48c40>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'
..\rpython\rtyper\lltypesystem\lltype.py:1270: AttributeError
_______ ERROR at setup of AppTestCpythonExtension.test_export_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 0x000001d331022908>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=item, **kwds), when=when)
..\_pytest\runner.py:138:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_HookCaller 'pytest_runtest_setup'>
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_export_function'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_export_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 0x000001d327531440>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d32f2fcd60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001d3279f86a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d3279f86e0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_export_function'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_export_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 0x000001d32f2fcd60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001d3279f86a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d3279f86e0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_export_function'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_export_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_export_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 0x000001d32ea615b0>
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 0x000001d3315e33a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001d3315e33a0>
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_export_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_export_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 = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]}
config = <rpython.config.config.Config object at 0x000001d3315f81a8>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001d3315f81a8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001d3315f81a8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000001d3315f81a8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000001d3321eefe0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000001d32e39a330>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe499930a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49993060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49992ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000001d32c0def38>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x000001d3315f8720>, <W_TypeObject 'GenericAlias' at 0x1d32da46e20>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32e046fa8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32e046fa8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32e046fa8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32e046fa8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32cb49e10>>
w_obj = <W_TypeObject 'ellipsis' at 0x1d32e046fa8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x1d32e046fa8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32cb49e10>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x1d32e046fa8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32cb49e10>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32cb49e10>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32cb49e10>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'
..\rpython\rtyper\lltypesystem\lltype.py:1270: AttributeError
_______ ERROR at setup of AppTestCpythonExtension.test_export_docstring _______
self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'>
func = <function <lambda> at 0x000001d3326d1e98>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=item, **kwds), when=when)
..\_pytest\runner.py:138:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_HookCaller 'pytest_runtest_setup'>
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_export_docstring'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_export_docstring'>}
def __call__(self, **kwargs):
assert not self.is_historic()
> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
..\_pytest\vendored_packages\pluggy.py:724:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.config.PytestPluginManager object at 0x000001d327531440>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d32f2fcd60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001d3279f86a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d3279f86e0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_export_docstring'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_export_docstring'>}
def _hookexec(self, hook, methods, kwargs):
# called from all hookcaller instances.
# enable_tracing will set its own wrapping function at self._inner_hookexec
> return self._inner_hookexec(hook, methods, kwargs)
..\_pytest\vendored_packages\pluggy.py:338:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d32f2fcd60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001d3279f86a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d3279f86e0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_export_docstring'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_export_docstring'>}
self._inner_hookexec = lambda hook, methods, kwargs: \
> _MultiCall(methods, kwargs, hook.spec_opts).execute()
..\_pytest\vendored_packages\pluggy.py:333:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_export_docstring'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
> return _wrapped_call(hook_impl.function(*args), self.execute)
..\_pytest\vendored_packages\pluggy.py:595:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
wrap_controller = <generator object pytest_runtest_setup at 0x000001d32e313d58>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i..._docstring'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>>
def _wrapped_call(wrap_controller, func):
""" Wrap calling to a function with a generator which needs to yield
exactly once. The yield point will trigger calling the wrapped function
and return its _CallOutcome to the yield point. The generator then needs
to finish (raise StopIteration) in order for the wrapped call to complete.
"""
try:
next(wrap_controller) # first yield
except StopIteration:
_raise_wrapfail(wrap_controller, "did not yield")
call_outcome = _CallOutcome(func)
try:
wrap_controller.send(call_outcome)
_raise_wrapfail(wrap_controller, "has second yield")
except StopIteration:
pass
> return call_outcome.get_result()
..\_pytest\vendored_packages\pluggy.py:253:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001d331470ca0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001d331470ca0>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i..._docstring'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>>
def __init__(self, func):
try:
> self.result = func()
..\_pytest\vendored_packages\pluggy.py:264:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_export_docstring'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
return _wrapped_call(hook_impl.function(*args), self.execute)
> res = hook_impl.function(*args)
..\_pytest\vendored_packages\pluggy.py:596:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
item = <AppTestMethod 'test_export_docstring'>
@pytest.hookimpl(tryfirst=True)
def pytest_runtest_setup(item):
if isinstance(item, pytest.Function):
config = item.config
if get_marker(item, name='pypy_only'):
if config.applevel is not None and not config.applevel.is_pypy:
pytest.skip('PyPy-specific test')
appclass = item.getparent(pytest.Class)
if appclass is not None:
from pypy.tool.pytest.objspace import gettestobjspace
# Make cls.space and cls.runappdirect available in tests.
spaceconfig = getattr(appclass.obj, 'spaceconfig', {})
> appclass.obj.space = gettestobjspace(**spaceconfig)
conftest.py:259:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]}
config = <rpython.config.config.Config object at 0x000001d33140f280>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001d33140f280>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001d33140f280>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000001d33140f280>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000001d331cf3320>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000001d32e18ec98>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe499930a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49993060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49992ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000001d32c0def38>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x000001d33140f7f8>, <W_TypeObject 'GenericAlias' at 0x1d32e06d8d8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32d7bd478>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32d7bd478>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32d7bd478>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32d7bd478>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32cb49360>>
w_obj = <W_TypeObject 'ellipsis' at 0x1d32d7bd478>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x1d32d7bd478>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32cb49360>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x1d32d7bd478>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32cb49360>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32cb49360>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32cb49360>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'
..\rpython\rtyper\lltypesystem\lltype.py:1270: AttributeError
_________ ERROR at setup of AppTestCpythonExtension.test_load_dynamic _________
self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'>
func = <function <lambda> at 0x000001d32e0adf88>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=item, **kwds), when=when)
..\_pytest\runner.py:138:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_HookCaller 'pytest_runtest_setup'>
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_load_dynamic'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_load_dynamic'>}
def __call__(self, **kwargs):
assert not self.is_historic()
> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
..\_pytest\vendored_packages\pluggy.py:724:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.config.PytestPluginManager object at 0x000001d327531440>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d32f2fcd60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001d3279f86a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d3279f86e0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_load_dynamic'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_load_dynamic'>}
def _hookexec(self, hook, methods, kwargs):
# called from all hookcaller instances.
# enable_tracing will set its own wrapping function at self._inner_hookexec
> return self._inner_hookexec(hook, methods, kwargs)
..\_pytest\vendored_packages\pluggy.py:338:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d32f2fcd60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001d3279f86a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d3279f86e0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_load_dynamic'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_load_dynamic'>}
self._inner_hookexec = lambda hook, methods, kwargs: \
> _MultiCall(methods, kwargs, hook.spec_opts).execute()
..\_pytest\vendored_packages\pluggy.py:333:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_load_dynamic'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
> return _wrapped_call(hook_impl.function(*args), self.execute)
..\_pytest\vendored_packages\pluggy.py:595:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
wrap_controller = <generator object pytest_runtest_setup at 0x000001d332859740>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ad_dynamic'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>>
def _wrapped_call(wrap_controller, func):
""" Wrap calling to a function with a generator which needs to yield
exactly once. The yield point will trigger calling the wrapped function
and return its _CallOutcome to the yield point. The generator then needs
to finish (raise StopIteration) in order for the wrapped call to complete.
"""
try:
next(wrap_controller) # first yield
except StopIteration:
_raise_wrapfail(wrap_controller, "did not yield")
call_outcome = _CallOutcome(func)
try:
wrap_controller.send(call_outcome)
_raise_wrapfail(wrap_controller, "has second yield")
except StopIteration:
pass
> return call_outcome.get_result()
..\_pytest\vendored_packages\pluggy.py:253:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001d3320041e0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001d3320041e0>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ad_dynamic'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>>
def __init__(self, func):
try:
> self.result = func()
..\_pytest\vendored_packages\pluggy.py:264:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_load_dynamic'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
return _wrapped_call(hook_impl.function(*args), self.execute)
> res = hook_impl.function(*args)
..\_pytest\vendored_packages\pluggy.py:596:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
item = <AppTestMethod 'test_load_dynamic'>
@pytest.hookimpl(tryfirst=True)
def pytest_runtest_setup(item):
if isinstance(item, pytest.Function):
config = item.config
if get_marker(item, name='pypy_only'):
if config.applevel is not None and not config.applevel.is_pypy:
pytest.skip('PyPy-specific test')
appclass = item.getparent(pytest.Class)
if appclass is not None:
from pypy.tool.pytest.objspace import gettestobjspace
# Make cls.space and cls.runappdirect available in tests.
spaceconfig = getattr(appclass.obj, 'spaceconfig', {})
> appclass.obj.space = gettestobjspace(**spaceconfig)
conftest.py:259:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]}
config = <rpython.config.config.Config object at 0x000001d331fee100>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001d331fee100>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001d331fee100>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000001d331fee100>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000001d331b514e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000001d32e3f6a30>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe499930a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49993060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49992ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000001d32c0def38>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x000001d331fee678>, <W_TypeObject 'GenericAlias' at 0x1d32e565ad0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32e06c8a8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32e06c8a8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32e06c8a8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32e06c8a8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32cb496f0>>
w_obj = <W_TypeObject 'ellipsis' at 0x1d32e06c8a8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x1d32e06c8a8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32cb496f0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x1d32e06c8a8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32cb496f0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32cb496f0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32cb496f0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'
..\rpython\rtyper\lltypesystem\lltype.py:1270: AttributeError
______ ERROR at setup of AppTestCpythonExtension.test_InitModule4_dotted ______
self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'>
func = <function <lambda> at 0x000001d331cfe110>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=item, **kwds), when=when)
..\_pytest\runner.py:138:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_HookCaller 'pytest_runtest_setup'>
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_InitModule4_dotted'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_InitModule4_dotted'>}
def __call__(self, **kwargs):
assert not self.is_historic()
> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
..\_pytest\vendored_packages\pluggy.py:724:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.config.PytestPluginManager object at 0x000001d327531440>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d32f2fcd60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001d3279f86a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d3279f86e0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_InitModule4_dotted'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_InitModule4_dotted'>}
def _hookexec(self, hook, methods, kwargs):
# called from all hookcaller instances.
# enable_tracing will set its own wrapping function at self._inner_hookexec
> return self._inner_hookexec(hook, methods, kwargs)
..\_pytest\vendored_packages\pluggy.py:338:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d32f2fcd60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001d3279f86a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d3279f86e0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_InitModule4_dotted'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_InitModule4_dotted'>}
self._inner_hookexec = lambda hook, methods, kwargs: \
> _MultiCall(methods, kwargs, hook.spec_opts).execute()
..\_pytest\vendored_packages\pluggy.py:333:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_InitModule4_dotted'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
> return _wrapped_call(hook_impl.function(*args), self.execute)
..\_pytest\vendored_packages\pluggy.py:595:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
wrap_controller = <generator object pytest_runtest_setup at 0x000001d32aee3330>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...le4_dotted'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>>
def _wrapped_call(wrap_controller, func):
""" Wrap calling to a function with a generator which needs to yield
exactly once. The yield point will trigger calling the wrapped function
and return its _CallOutcome to the yield point. The generator then needs
to finish (raise StopIteration) in order for the wrapped call to complete.
"""
try:
next(wrap_controller) # first yield
except StopIteration:
_raise_wrapfail(wrap_controller, "did not yield")
call_outcome = _CallOutcome(func)
try:
wrap_controller.send(call_outcome)
_raise_wrapfail(wrap_controller, "has second yield")
except StopIteration:
pass
> return call_outcome.get_result()
..\_pytest\vendored_packages\pluggy.py:253:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001d33128eae0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001d33128eae0>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...le4_dotted'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>>
def __init__(self, func):
try:
> self.result = func()
..\_pytest\vendored_packages\pluggy.py:264:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_InitModule4_dotted'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
return _wrapped_call(hook_impl.function(*args), self.execute)
> res = hook_impl.function(*args)
..\_pytest\vendored_packages\pluggy.py:596:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
item = <AppTestMethod 'test_InitModule4_dotted'>
@pytest.hookimpl(tryfirst=True)
def pytest_runtest_setup(item):
if isinstance(item, pytest.Function):
config = item.config
if get_marker(item, name='pypy_only'):
if config.applevel is not None and not config.applevel.is_pypy:
pytest.skip('PyPy-specific test')
appclass = item.getparent(pytest.Class)
if appclass is not None:
from pypy.tool.pytest.objspace import gettestobjspace
# Make cls.space and cls.runappdirect available in tests.
spaceconfig = getattr(appclass.obj, 'spaceconfig', {})
> appclass.obj.space = gettestobjspace(**spaceconfig)
conftest.py:259:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]}
config = <rpython.config.config.Config object at 0x000001d3312d3da8>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001d3312d3da8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001d3312d3da8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000001d3312d3da8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000001d33128fe60>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000001d32da99868>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe499930a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49993060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49992ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000001d32c0def38>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x000001d332054368>, <W_TypeObject 'GenericAlias' at 0x1d32e78e4b8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32e4691a0>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32e4691a0>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32e4691a0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32e4691a0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32cb46c30>>
w_obj = <W_TypeObject 'ellipsis' at 0x1d32e4691a0>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x1d32e4691a0>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32cb46c30>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x1d32e4691a0>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32cb46c30>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32cb46c30>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32cb46c30>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'
..\rpython\rtyper\lltypesystem\lltype.py:1270: AttributeError
____ ERROR at setup of AppTestCpythonExtension.test_InitModule4_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 0x000001d32e49b1f0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=item, **kwds), when=when)
..\_pytest\runner.py:138:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_HookCaller 'pytest_runtest_setup'>
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_InitModule4_in_package'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_InitModule4_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 0x000001d327531440>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d32f2fcd60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001d3279f86a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d3279f86e0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_InitModule4_in_package'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_InitModule4_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 0x000001d32f2fcd60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001d3279f86a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d3279f86e0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_InitModule4_in_package'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_InitModule4_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_InitModule4_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 0x000001d32e1970b0>
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 0x000001d330a8f5e0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001d330a8f5e0>
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_InitModule4_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_InitModule4_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 = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]}
config = <rpython.config.config.Config object at 0x000001d3311af360>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001d3311af360>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001d3311af360>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000001d3311af360>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000001d33142e9a0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000001d32e4422c0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe499930a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49993060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49992ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000001d32c0def38>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x000001d3311afad0>, <W_TypeObject 'GenericAlias' at 0x1d32e840f70>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32e51d7c0>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32e51d7c0>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32e51d7c0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32e51d7c0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32cb47350>>
w_obj = <W_TypeObject 'ellipsis' at 0x1d32e51d7c0>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x1d32e51d7c0>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32cb47350>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x1d32e51d7c0>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32cb47350>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32cb47350>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32cb47350>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'
..\rpython\rtyper\lltypesystem\lltype.py:1270: AttributeError
___ ERROR at setup of AppTestCpythonExtension.test_recursive_package_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 0x000001d332822ae8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=item, **kwds), when=when)
..\_pytest\runner.py:138:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_HookCaller 'pytest_runtest_setup'>
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_recursive_package_import'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_recursive_package_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 0x000001d327531440>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d32f2fcd60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001d3279f86a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d3279f86e0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_recursive_package_import'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_recursive_package_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 0x000001d32f2fcd60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001d3279f86a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d3279f86e0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_recursive_package_import'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_recursive_package_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_recursive_package_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 0x000001d32e3d6688>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...age_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 0x000001d330b7f1e0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001d330b7f1e0>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...age_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_recursive_package_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_recursive_package_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 0x000001d330c1d360>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001d330c1d360>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001d330c1d360>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000001d330c1d360>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000001d3310b2b60>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000001d32da86f38>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe499530a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49953060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49952ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000001d32c0def38>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x000001d330c1d8d8>, <W_TypeObject 'GenericAlias' at 0x1d32e8674b0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32e2a3d38>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32e2a3d38>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32e2a3d38>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32e2a3d38>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32cb476e0>>
w_obj = <W_TypeObject 'ellipsis' at 0x1d32e2a3d38>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x1d32e2a3d38>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32cb476e0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x1d32e2a3d38>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32cb476e0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32cb476e0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32cb476e0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'
..\rpython\rtyper\lltypesystem\lltype.py:1270: AttributeError
_________ ERROR at setup of AppTestCpythonExtension.test_modinit_func _________
self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'>
func = <function <lambda> at 0x000001d32d10f088>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=item, **kwds), when=when)
..\_pytest\runner.py:138:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_HookCaller 'pytest_runtest_setup'>
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_modinit_func'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_modinit_func'>}
def __call__(self, **kwargs):
assert not self.is_historic()
> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
..\_pytest\vendored_packages\pluggy.py:724:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.config.PytestPluginManager object at 0x000001d327531440>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d32f2fcd60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001d3279f86a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d3279f86e0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_modinit_func'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_modinit_func'>}
def _hookexec(self, hook, methods, kwargs):
# called from all hookcaller instances.
# enable_tracing will set its own wrapping function at self._inner_hookexec
> return self._inner_hookexec(hook, methods, kwargs)
..\_pytest\vendored_packages\pluggy.py:338:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d32f2fcd60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001d3279f86a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d3279f86e0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_modinit_func'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_modinit_func'>}
self._inner_hookexec = lambda hook, methods, kwargs: \
> _MultiCall(methods, kwargs, hook.spec_opts).execute()
..\_pytest\vendored_packages\pluggy.py:333:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_modinit_func'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
> return _wrapped_call(hook_impl.function(*args), self.execute)
..\_pytest\vendored_packages\pluggy.py:595:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
wrap_controller = <generator object pytest_runtest_setup at 0x000001d3327842f0>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...dinit_func'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>>
def _wrapped_call(wrap_controller, func):
""" Wrap calling to a function with a generator which needs to yield
exactly once. The yield point will trigger calling the wrapped function
and return its _CallOutcome to the yield point. The generator then needs
to finish (raise StopIteration) in order for the wrapped call to complete.
"""
try:
next(wrap_controller) # first yield
except StopIteration:
_raise_wrapfail(wrap_controller, "did not yield")
call_outcome = _CallOutcome(func)
try:
wrap_controller.send(call_outcome)
_raise_wrapfail(wrap_controller, "has second yield")
except StopIteration:
pass
> return call_outcome.get_result()
..\_pytest\vendored_packages\pluggy.py:253:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001d3320740a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001d3320740a0>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...dinit_func'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>>
def __init__(self, func):
try:
> self.result = func()
..\_pytest\vendored_packages\pluggy.py:264:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_modinit_func'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
return _wrapped_call(hook_impl.function(*args), self.execute)
> res = hook_impl.function(*args)
..\_pytest\vendored_packages\pluggy.py:596:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
item = <AppTestMethod 'test_modinit_func'>
@pytest.hookimpl(tryfirst=True)
def pytest_runtest_setup(item):
if isinstance(item, pytest.Function):
config = item.config
if get_marker(item, name='pypy_only'):
if config.applevel is not None and not config.applevel.is_pypy:
pytest.skip('PyPy-specific test')
appclass = item.getparent(pytest.Class)
if appclass is not None:
from pypy.tool.pytest.objspace import gettestobjspace
# Make cls.space and cls.runappdirect available in tests.
spaceconfig = getattr(appclass.obj, 'spaceconfig', {})
> appclass.obj.space = gettestobjspace(**spaceconfig)
conftest.py:259:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]}
config = <rpython.config.config.Config object at 0x000001d331693da8>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001d331693da8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001d331693da8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000001d331693da8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000001d3320754e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000001d32882d670>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe499930a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49993060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49992ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000001d32c0def38>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x000001d33208c368>, <W_TypeObject 'GenericAlias' at 0x1d32e827130>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32e51d6e0>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32e51d6e0>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32e51d6e0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32e51d6e0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32cb488b0>>
w_obj = <W_TypeObject 'ellipsis' at 0x1d32e51d6e0>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x1d32e51d6e0>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32cb488b0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x1d32e51d6e0>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32cb488b0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32cb488b0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32cb488b0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'
..\rpython\rtyper\lltypesystem\lltype.py:1270: AttributeError
_______ ERROR at setup of AppTestCpythonExtension.test_export_function2 _______
self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'>
func = <function <lambda> at 0x000001d32ebd0ae8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=item, **kwds), when=when)
..\_pytest\runner.py:138:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_HookCaller 'pytest_runtest_setup'>
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_export_function2'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_export_function2'>}
def __call__(self, **kwargs):
assert not self.is_historic()
> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
..\_pytest\vendored_packages\pluggy.py:724:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.config.PytestPluginManager object at 0x000001d327531440>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d32f2fcd60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001d3279f86a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d3279f86e0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_export_function2'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_export_function2'>}
def _hookexec(self, hook, methods, kwargs):
# called from all hookcaller instances.
# enable_tracing will set its own wrapping function at self._inner_hookexec
> return self._inner_hookexec(hook, methods, kwargs)
..\_pytest\vendored_packages\pluggy.py:338:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d32f2fcd60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001d3279f86a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d3279f86e0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_export_function2'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_export_function2'>}
self._inner_hookexec = lambda hook, methods, kwargs: \
> _MultiCall(methods, kwargs, hook.spec_opts).execute()
..\_pytest\vendored_packages\pluggy.py:333:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_export_function2'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
> return _wrapped_call(hook_impl.function(*args), self.execute)
..\_pytest\vendored_packages\pluggy.py:595:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
wrap_controller = <generator object pytest_runtest_setup at 0x000001d32da5a5c0>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i..._function2'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>>
def _wrapped_call(wrap_controller, func):
""" Wrap calling to a function with a generator which needs to yield
exactly once. The yield point will trigger calling the wrapped function
and return its _CallOutcome to the yield point. The generator then needs
to finish (raise StopIteration) in order for the wrapped call to complete.
"""
try:
next(wrap_controller) # first yield
except StopIteration:
_raise_wrapfail(wrap_controller, "did not yield")
call_outcome = _CallOutcome(func)
try:
wrap_controller.send(call_outcome)
_raise_wrapfail(wrap_controller, "has second yield")
except StopIteration:
pass
> return call_outcome.get_result()
..\_pytest\vendored_packages\pluggy.py:253:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001d331fa18a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001d331fa18a0>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i..._function2'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>>
def __init__(self, func):
try:
> self.result = func()
..\_pytest\vendored_packages\pluggy.py:264:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_export_function2'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
return _wrapped_call(hook_impl.function(*args), self.execute)
> res = hook_impl.function(*args)
..\_pytest\vendored_packages\pluggy.py:596:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
item = <AppTestMethod 'test_export_function2'>
@pytest.hookimpl(tryfirst=True)
def pytest_runtest_setup(item):
if isinstance(item, pytest.Function):
config = item.config
if get_marker(item, name='pypy_only'):
if config.applevel is not None and not config.applevel.is_pypy:
pytest.skip('PyPy-specific test')
appclass = item.getparent(pytest.Class)
if appclass is not None:
from pypy.tool.pytest.objspace import gettestobjspace
# Make cls.space and cls.runappdirect available in tests.
spaceconfig = getattr(appclass.obj, 'spaceconfig', {})
> appclass.obj.space = gettestobjspace(**spaceconfig)
conftest.py:259:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]}
config = <rpython.config.config.Config object at 0x000001d3311f20c8>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001d3311f20c8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001d3311f20c8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000001d3311f20c8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000001d330aa5160>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000001d3318b2058>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe499530a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49953060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49952ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000001d32c0def38>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x000001d3311f2640>, <W_TypeObject 'GenericAlias' at 0x1d32e8af2f0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32e4ff088>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32e4ff088>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32e4ff088>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32e4ff088>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d327a355b0>>
w_obj = <W_TypeObject 'ellipsis' at 0x1d32e4ff088>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x1d32e4ff088>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d327a355b0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x1d32e4ff088>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d327a355b0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d327a355b0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d327a355b0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'
..\rpython\rtyper\lltypesystem\lltype.py:1270: AttributeError
___________ ERROR at setup of AppTestCpythonExtension.test_argument ___________
self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'>
func = <function <lambda> at 0x000001d331022728>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=item, **kwds), when=when)
..\_pytest\runner.py:138:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_HookCaller 'pytest_runtest_setup'>
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_argument'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_argument'>}
def __call__(self, **kwargs):
assert not self.is_historic()
> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
..\_pytest\vendored_packages\pluggy.py:724:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.config.PytestPluginManager object at 0x000001d327531440>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d32f2fcd60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001d3279f86a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d3279f86e0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_argument'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_argument'>}
def _hookexec(self, hook, methods, kwargs):
# called from all hookcaller instances.
# enable_tracing will set its own wrapping function at self._inner_hookexec
> return self._inner_hookexec(hook, methods, kwargs)
..\_pytest\vendored_packages\pluggy.py:338:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d32f2fcd60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001d3279f86a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d3279f86e0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_argument'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_argument'>}
self._inner_hookexec = lambda hook, methods, kwargs: \
> _MultiCall(methods, kwargs, hook.spec_opts).execute()
..\_pytest\vendored_packages\pluggy.py:333:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_argument'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
> return _wrapped_call(hook_impl.function(*args), self.execute)
..\_pytest\vendored_packages\pluggy.py:595:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
wrap_controller = <generator object pytest_runtest_setup at 0x000001d32e196de0>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...t_argument'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>>
def _wrapped_call(wrap_controller, func):
""" Wrap calling to a function with a generator which needs to yield
exactly once. The yield point will trigger calling the wrapped function
and return its _CallOutcome to the yield point. The generator then needs
to finish (raise StopIteration) in order for the wrapped call to complete.
"""
try:
next(wrap_controller) # first yield
except StopIteration:
_raise_wrapfail(wrap_controller, "did not yield")
call_outcome = _CallOutcome(func)
try:
wrap_controller.send(call_outcome)
_raise_wrapfail(wrap_controller, "has second yield")
except StopIteration:
pass
> return call_outcome.get_result()
..\_pytest\vendored_packages\pluggy.py:253:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001d33113f3a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001d33113f3a0>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...t_argument'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>>
def __init__(self, func):
try:
> self.result = func()
..\_pytest\vendored_packages\pluggy.py:264:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_argument'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
return _wrapped_call(hook_impl.function(*args), self.execute)
> res = hook_impl.function(*args)
..\_pytest\vendored_packages\pluggy.py:596:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
item = <AppTestMethod 'test_argument'>
@pytest.hookimpl(tryfirst=True)
def pytest_runtest_setup(item):
if isinstance(item, pytest.Function):
config = item.config
if get_marker(item, name='pypy_only'):
if config.applevel is not None and not config.applevel.is_pypy:
pytest.skip('PyPy-specific test')
appclass = item.getparent(pytest.Class)
if appclass is not None:
from pypy.tool.pytest.objspace import gettestobjspace
# Make cls.space and cls.runappdirect available in tests.
spaceconfig = getattr(appclass.obj, 'spaceconfig', {})
> appclass.obj.space = gettestobjspace(**spaceconfig)
conftest.py:259:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]}
config = <rpython.config.config.Config object at 0x000001d33065f910>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001d33065f910>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001d33065f910>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000001d33065f910>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000001d3316e2820>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000001d32e699f30>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe499930a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49993060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49992ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000001d32c0def38>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x000001d33065fe88>, <W_TypeObject 'GenericAlias' at 0x1d32e9ac2f8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32e5ad2f0>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32e5ad2f0>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32e5ad2f0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32e5ad2f0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d327a35cd0>>
w_obj = <W_TypeObject 'ellipsis' at 0x1d32e5ad2f0>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x1d32e5ad2f0>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d327a35cd0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x1d32e5ad2f0>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d327a35cd0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d327a35cd0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d327a35cd0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'
..\rpython\rtyper\lltypesystem\lltype.py:1270: AttributeError
__________ ERROR at setup of AppTestCpythonExtension.test_exception ___________
self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'>
func = <function <lambda> at 0x000001d331282278>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=item, **kwds), when=when)
..\_pytest\runner.py:138:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_HookCaller 'pytest_runtest_setup'>
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_exception'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_exception'>}
def __call__(self, **kwargs):
assert not self.is_historic()
> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
..\_pytest\vendored_packages\pluggy.py:724:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.config.PytestPluginManager object at 0x000001d327531440>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d32f2fcd60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001d3279f86a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d3279f86e0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_exception'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_exception'>}
def _hookexec(self, hook, methods, kwargs):
# called from all hookcaller instances.
# enable_tracing will set its own wrapping function at self._inner_hookexec
> return self._inner_hookexec(hook, methods, kwargs)
..\_pytest\vendored_packages\pluggy.py:338:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d32f2fcd60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001d3279f86a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d3279f86e0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_exception'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_exception'>}
self._inner_hookexec = lambda hook, methods, kwargs: \
> _MultiCall(methods, kwargs, hook.spec_opts).execute()
..\_pytest\vendored_packages\pluggy.py:333:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_exception'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
> return _wrapped_call(hook_impl.function(*args), self.execute)
..\_pytest\vendored_packages\pluggy.py:595:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
wrap_controller = <generator object pytest_runtest_setup at 0x000001d3326f0278>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i..._exception'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>>
def _wrapped_call(wrap_controller, func):
""" Wrap calling to a function with a generator which needs to yield
exactly once. The yield point will trigger calling the wrapped function
and return its _CallOutcome to the yield point. The generator then needs
to finish (raise StopIteration) in order for the wrapped call to complete.
"""
try:
next(wrap_controller) # first yield
except StopIteration:
_raise_wrapfail(wrap_controller, "did not yield")
call_outcome = _CallOutcome(func)
try:
wrap_controller.send(call_outcome)
_raise_wrapfail(wrap_controller, "has second yield")
except StopIteration:
pass
> return call_outcome.get_result()
..\_pytest\vendored_packages\pluggy.py:253:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001d330694a20>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001d330694a20>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i..._exception'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>>
def __init__(self, func):
try:
> self.result = func()
..\_pytest\vendored_packages\pluggy.py:264:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_exception'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
return _wrapped_call(hook_impl.function(*args), self.execute)
> res = hook_impl.function(*args)
..\_pytest\vendored_packages\pluggy.py:596:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
item = <AppTestMethod 'test_exception'>
@pytest.hookimpl(tryfirst=True)
def pytest_runtest_setup(item):
if isinstance(item, pytest.Function):
config = item.config
if get_marker(item, name='pypy_only'):
if config.applevel is not None and not config.applevel.is_pypy:
pytest.skip('PyPy-specific test')
appclass = item.getparent(pytest.Class)
if appclass is not None:
from pypy.tool.pytest.objspace import gettestobjspace
# Make cls.space and cls.runappdirect available in tests.
spaceconfig = getattr(appclass.obj, 'spaceconfig', {})
> appclass.obj.space = gettestobjspace(**spaceconfig)
conftest.py:259:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]}
config = <rpython.config.config.Config object at 0x000001d33065c608>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001d33065c608>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001d33065c608>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000001d33065c608>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000001d330695c20>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000001d330efc640>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe499930a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49993060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49992ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000001d32c0def38>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x000001d33065cb80>, <W_TypeObject 'GenericAlias' at 0x1d32e9bc3d8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32e5657f8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32e5657f8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32e5657f8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32e5657f8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32cb49a80>>
w_obj = <W_TypeObject 'ellipsis' at 0x1d32e5657f8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x1d32e5657f8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32cb49a80>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x1d32e5657f8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32cb49a80>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32cb49a80>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32cb49a80>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'
..\rpython\rtyper\lltypesystem\lltype.py:1270: AttributeError
___________ ERROR at setup of AppTestCpythonExtension.test_refcount ___________
self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'>
func = <function <lambda> at 0x000001d331cfe908>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=item, **kwds), when=when)
..\_pytest\runner.py:138:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_HookCaller 'pytest_runtest_setup'>
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_refcount'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_refcount'>}
def __call__(self, **kwargs):
assert not self.is_historic()
> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
..\_pytest\vendored_packages\pluggy.py:724:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.config.PytestPluginManager object at 0x000001d327531440>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d32f2fcd60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001d3279f86a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d3279f86e0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_refcount'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_refcount'>}
def _hookexec(self, hook, methods, kwargs):
# called from all hookcaller instances.
# enable_tracing will set its own wrapping function at self._inner_hookexec
> return self._inner_hookexec(hook, methods, kwargs)
..\_pytest\vendored_packages\pluggy.py:338:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d32f2fcd60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001d3279f86a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d3279f86e0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_refcount'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_refcount'>}
self._inner_hookexec = lambda hook, methods, kwargs: \
> _MultiCall(methods, kwargs, hook.spec_opts).execute()
..\_pytest\vendored_packages\pluggy.py:333:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_refcount'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
> return _wrapped_call(hook_impl.function(*args), self.execute)
..\_pytest\vendored_packages\pluggy.py:595:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
wrap_controller = <generator object pytest_runtest_setup at 0x000001d332800318>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...t_refcount'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>>
def _wrapped_call(wrap_controller, func):
""" Wrap calling to a function with a generator which needs to yield
exactly once. The yield point will trigger calling the wrapped function
and return its _CallOutcome to the yield point. The generator then needs
to finish (raise StopIteration) in order for the wrapped call to complete.
"""
try:
next(wrap_controller) # first yield
except StopIteration:
_raise_wrapfail(wrap_controller, "did not yield")
call_outcome = _CallOutcome(func)
try:
wrap_controller.send(call_outcome)
_raise_wrapfail(wrap_controller, "has second yield")
except StopIteration:
pass
> return call_outcome.get_result()
..\_pytest\vendored_packages\pluggy.py:253:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001d330ec7120>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001d330ec7120>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...t_refcount'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>>
def __init__(self, func):
try:
> self.result = func()
..\_pytest\vendored_packages\pluggy.py:264:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_refcount'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
return _wrapped_call(hook_impl.function(*args), self.execute)
> res = hook_impl.function(*args)
..\_pytest\vendored_packages\pluggy.py:596:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
item = <AppTestMethod 'test_refcount'>
@pytest.hookimpl(tryfirst=True)
def pytest_runtest_setup(item):
if isinstance(item, pytest.Function):
config = item.config
if get_marker(item, name='pypy_only'):
if config.applevel is not None and not config.applevel.is_pypy:
pytest.skip('PyPy-specific test')
appclass = item.getparent(pytest.Class)
if appclass is not None:
from pypy.tool.pytest.objspace import gettestobjspace
# Make cls.space and cls.runappdirect available in tests.
spaceconfig = getattr(appclass.obj, 'spaceconfig', {})
> appclass.obj.space = gettestobjspace(**spaceconfig)
conftest.py:259:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]}
config = <rpython.config.config.Config object at 0x000001d331677130>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001d331677130>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001d331677130>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000001d331677130>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000001d330ef8520>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000001d330efda60>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe499530a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49953060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49952ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000001d32c0def38>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x000001d3316776a8>, <W_TypeObject 'GenericAlias' at 0x1d32ea28448>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32e618c28>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32e618c28>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32e618c28>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32e618c28>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d327a363f0>>
w_obj = <W_TypeObject 'ellipsis' at 0x1d32e618c28>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x1d32e618c28>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d327a363f0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x1d32e618c28>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d327a363f0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d327a363f0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d327a363f0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'
..\rpython\rtyper\lltypesystem\lltype.py:1270: AttributeError
________ ERROR at setup of AppTestCpythonExtension.test_init_exception ________
self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'>
func = <function <lambda> at 0x000001d332822ae8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=item, **kwds), when=when)
..\_pytest\runner.py:138:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_HookCaller 'pytest_runtest_setup'>
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_init_exception'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_init_exception'>}
def __call__(self, **kwargs):
assert not self.is_historic()
> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
..\_pytest\vendored_packages\pluggy.py:724:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.config.PytestPluginManager object at 0x000001d327531440>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d32f2fcd60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001d3279f86a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d3279f86e0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_init_exception'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_init_exception'>}
def _hookexec(self, hook, methods, kwargs):
# called from all hookcaller instances.
# enable_tracing will set its own wrapping function at self._inner_hookexec
> return self._inner_hookexec(hook, methods, kwargs)
..\_pytest\vendored_packages\pluggy.py:338:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d32f2fcd60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001d3279f86a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d3279f86e0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_init_exception'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_init_exception'>}
self._inner_hookexec = lambda hook, methods, kwargs: \
> _MultiCall(methods, kwargs, hook.spec_opts).execute()
..\_pytest\vendored_packages\pluggy.py:333:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_init_exception'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
> return _wrapped_call(hook_impl.function(*args), self.execute)
..\_pytest\vendored_packages\pluggy.py:595:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
wrap_controller = <generator object pytest_runtest_setup at 0x000001d32d605df8>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i..._exception'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>>
def _wrapped_call(wrap_controller, func):
""" Wrap calling to a function with a generator which needs to yield
exactly once. The yield point will trigger calling the wrapped function
and return its _CallOutcome to the yield point. The generator then needs
to finish (raise StopIteration) in order for the wrapped call to complete.
"""
try:
next(wrap_controller) # first yield
except StopIteration:
_raise_wrapfail(wrap_controller, "did not yield")
call_outcome = _CallOutcome(func)
try:
wrap_controller.send(call_outcome)
_raise_wrapfail(wrap_controller, "has second yield")
except StopIteration:
pass
> return call_outcome.get_result()
..\_pytest\vendored_packages\pluggy.py:253:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001d331931160>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001d331931160>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i..._exception'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>>
def __init__(self, func):
try:
> self.result = func()
..\_pytest\vendored_packages\pluggy.py:264:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_init_exception'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
return _wrapped_call(hook_impl.function(*args), self.execute)
> res = hook_impl.function(*args)
..\_pytest\vendored_packages\pluggy.py:596:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
item = <AppTestMethod 'test_init_exception'>
@pytest.hookimpl(tryfirst=True)
def pytest_runtest_setup(item):
if isinstance(item, pytest.Function):
config = item.config
if get_marker(item, name='pypy_only'):
if config.applevel is not None and not config.applevel.is_pypy:
pytest.skip('PyPy-specific test')
appclass = item.getparent(pytest.Class)
if appclass is not None:
from pypy.tool.pytest.objspace import gettestobjspace
# Make cls.space and cls.runappdirect available in tests.
spaceconfig = getattr(appclass.obj, 'spaceconfig', {})
> appclass.obj.space = gettestobjspace(**spaceconfig)
conftest.py:259:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]}
config = <rpython.config.config.Config object at 0x000001d33192e918>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001d33192e918>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001d33192e918>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000001d33192e918>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000001d330b30220>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000001d330e66608>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe499530a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49953060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49952ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000001d32c0def38>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x000001d33192ee90>, <W_TypeObject 'GenericAlias' at 0x1d32eb43088>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32e5c3de0>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32e5c3de0>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32e5c3de0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32e5c3de0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32ce724b0>>
w_obj = <W_TypeObject 'ellipsis' at 0x1d32e5c3de0>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x1d32e5c3de0>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32ce724b0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x1d32e5c3de0>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32ce724b0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32ce724b0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32ce724b0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'
..\rpython\rtyper\lltypesystem\lltype.py:1270: AttributeError
_____ ERROR at setup of AppTestCpythonExtension.test_internal_exceptions ______
self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'>
func = <function <lambda> at 0x000001d32e3ef790>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=item, **kwds), when=when)
..\_pytest\runner.py:138:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_HookCaller 'pytest_runtest_setup'>
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_internal_exceptions'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_internal_exceptions'>}
def __call__(self, **kwargs):
assert not self.is_historic()
> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
..\_pytest\vendored_packages\pluggy.py:724:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.config.PytestPluginManager object at 0x000001d327531440>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d32f2fcd60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001d3279f86a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d3279f86e0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_internal_exceptions'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_internal_exceptions'>}
def _hookexec(self, hook, methods, kwargs):
# called from all hookcaller instances.
# enable_tracing will set its own wrapping function at self._inner_hookexec
> return self._inner_hookexec(hook, methods, kwargs)
..\_pytest\vendored_packages\pluggy.py:338:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d32f2fcd60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001d3279f86a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d3279f86e0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_internal_exceptions'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_internal_exceptions'>}
self._inner_hookexec = lambda hook, methods, kwargs: \
> _MultiCall(methods, kwargs, hook.spec_opts).execute()
..\_pytest\vendored_packages\pluggy.py:333:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_internal_exceptions'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
> return _wrapped_call(hook_impl.function(*args), self.execute)
..\_pytest\vendored_packages\pluggy.py:595:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
wrap_controller = <generator object pytest_runtest_setup at 0x000001d32e1ea098>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...exceptions'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>>
def _wrapped_call(wrap_controller, func):
""" Wrap calling to a function with a generator which needs to yield
exactly once. The yield point will trigger calling the wrapped function
and return its _CallOutcome to the yield point. The generator then needs
to finish (raise StopIteration) in order for the wrapped call to complete.
"""
try:
next(wrap_controller) # first yield
except StopIteration:
_raise_wrapfail(wrap_controller, "did not yield")
call_outcome = _CallOutcome(func)
try:
wrap_controller.send(call_outcome)
_raise_wrapfail(wrap_controller, "has second yield")
except StopIteration:
pass
> return call_outcome.get_result()
..\_pytest\vendored_packages\pluggy.py:253:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001d3312bad60>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001d3312bad60>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...exceptions'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>>
def __init__(self, func):
try:
> self.result = func()
..\_pytest\vendored_packages\pluggy.py:264:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_internal_exceptions'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
return _wrapped_call(hook_impl.function(*args), self.execute)
> res = hook_impl.function(*args)
..\_pytest\vendored_packages\pluggy.py:596:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
item = <AppTestMethod 'test_internal_exceptions'>
@pytest.hookimpl(tryfirst=True)
def pytest_runtest_setup(item):
if isinstance(item, pytest.Function):
config = item.config
if get_marker(item, name='pypy_only'):
if config.applevel is not None and not config.applevel.is_pypy:
pytest.skip('PyPy-specific test')
appclass = item.getparent(pytest.Class)
if appclass is not None:
from pypy.tool.pytest.objspace import gettestobjspace
# Make cls.space and cls.runappdirect available in tests.
spaceconfig = getattr(appclass.obj, 'spaceconfig', {})
> appclass.obj.space = gettestobjspace(**spaceconfig)
conftest.py:259:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]}
config = <rpython.config.config.Config object at 0x000001d3312ee918>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001d3312ee918>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001d3312ee918>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000001d3312ee918>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000001d3312bbee0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000001d331ff99f0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe499930a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49993060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49992ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000001d32c0def38>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x000001d3312eee90>, <W_TypeObject 'GenericAlias' at 0x1d32e9ac0c8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32e596058>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32e596058>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32e596058>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32e596058>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32ce70110>>
w_obj = <W_TypeObject 'ellipsis' at 0x1d32e596058>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x1d32e596058>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32ce70110>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x1d32e596058>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32ce70110>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32ce70110>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32ce70110>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'
..\rpython\rtyper\lltypesystem\lltype.py:1270: AttributeError
________ ERROR at setup of AppTestCpythonExtension.test_new_exception _________
self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'>
func = <function <lambda> at 0x000001d32d1b0908>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=item, **kwds), when=when)
..\_pytest\runner.py:138:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_HookCaller 'pytest_runtest_setup'>
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_new_exception'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_new_exception'>}
def __call__(self, **kwargs):
assert not self.is_historic()
> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
..\_pytest\vendored_packages\pluggy.py:724:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.config.PytestPluginManager object at 0x000001d327531440>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d32f2fcd60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001d3279f86a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d3279f86e0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_new_exception'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_new_exception'>}
def _hookexec(self, hook, methods, kwargs):
# called from all hookcaller instances.
# enable_tracing will set its own wrapping function at self._inner_hookexec
> return self._inner_hookexec(hook, methods, kwargs)
..\_pytest\vendored_packages\pluggy.py:338:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d32f2fcd60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001d3279f86a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d3279f86e0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_new_exception'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_new_exception'>}
self._inner_hookexec = lambda hook, methods, kwargs: \
> _MultiCall(methods, kwargs, hook.spec_opts).execute()
..\_pytest\vendored_packages\pluggy.py:333:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_new_exception'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
> return _wrapped_call(hook_impl.function(*args), self.execute)
..\_pytest\vendored_packages\pluggy.py:595:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
wrap_controller = <generator object pytest_runtest_setup at 0x000001d32c523d30>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i..._exception'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>>
def _wrapped_call(wrap_controller, func):
""" Wrap calling to a function with a generator which needs to yield
exactly once. The yield point will trigger calling the wrapped function
and return its _CallOutcome to the yield point. The generator then needs
to finish (raise StopIteration) in order for the wrapped call to complete.
"""
try:
next(wrap_controller) # first yield
except StopIteration:
_raise_wrapfail(wrap_controller, "did not yield")
call_outcome = _CallOutcome(func)
try:
wrap_controller.send(call_outcome)
_raise_wrapfail(wrap_controller, "has second yield")
except StopIteration:
pass
> return call_outcome.get_result()
..\_pytest\vendored_packages\pluggy.py:253:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001d331c966a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001d331c966a0>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i..._exception'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>>
def __init__(self, func):
try:
> self.result = func()
..\_pytest\vendored_packages\pluggy.py:264:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_new_exception'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
return _wrapped_call(hook_impl.function(*args), self.execute)
> res = hook_impl.function(*args)
..\_pytest\vendored_packages\pluggy.py:596:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
item = <AppTestMethod 'test_new_exception'>
@pytest.hookimpl(tryfirst=True)
def pytest_runtest_setup(item):
if isinstance(item, pytest.Function):
config = item.config
if get_marker(item, name='pypy_only'):
if config.applevel is not None and not config.applevel.is_pypy:
pytest.skip('PyPy-specific test')
appclass = item.getparent(pytest.Class)
if appclass is not None:
from pypy.tool.pytest.objspace import gettestobjspace
# Make cls.space and cls.runappdirect available in tests.
spaceconfig = getattr(appclass.obj, 'spaceconfig', {})
> appclass.obj.space = gettestobjspace(**spaceconfig)
conftest.py:259:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]}
config = <rpython.config.config.Config object at 0x000001d331cb3be8>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001d331cb3be8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001d331cb3be8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000001d331cb3be8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000001d331c97b60>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000001d330a90950>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe499930a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49993060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49992ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000001d32c0def38>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x000001d3318e81a8>, <W_TypeObject 'GenericAlias' at 0x1d32eb42d78>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32e564288>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32e564288>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32e564288>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32e564288>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32ce72840>>
w_obj = <W_TypeObject 'ellipsis' at 0x1d32e564288>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x1d32e564288>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32ce72840>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x1d32e564288>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32ce72840>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32ce72840>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32ce72840>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'
..\rpython\rtyper\lltypesystem\lltype.py:1270: AttributeError
_________ ERROR at setup of AppTestCpythonExtension.test_hash_pointer _________
self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'>
func = <function <lambda> at 0x000001d32f8b8bd8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=item, **kwds), when=when)
..\_pytest\runner.py:138:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_HookCaller 'pytest_runtest_setup'>
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_hash_pointer'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_hash_pointer'>}
def __call__(self, **kwargs):
assert not self.is_historic()
> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
..\_pytest\vendored_packages\pluggy.py:724:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.config.PytestPluginManager object at 0x000001d327531440>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d32f2fcd60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001d3279f86a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d3279f86e0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_hash_pointer'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_hash_pointer'>}
def _hookexec(self, hook, methods, kwargs):
# called from all hookcaller instances.
# enable_tracing will set its own wrapping function at self._inner_hookexec
> return self._inner_hookexec(hook, methods, kwargs)
..\_pytest\vendored_packages\pluggy.py:338:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d32f2fcd60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001d3279f86a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d3279f86e0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_hash_pointer'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_hash_pointer'>}
self._inner_hookexec = lambda hook, methods, kwargs: \
> _MultiCall(methods, kwargs, hook.spec_opts).execute()
..\_pytest\vendored_packages\pluggy.py:333:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_hash_pointer'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
> return _wrapped_call(hook_impl.function(*args), self.execute)
..\_pytest\vendored_packages\pluggy.py:595:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
wrap_controller = <generator object pytest_runtest_setup at 0x000001d32c310520>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...sh_pointer'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>>
def _wrapped_call(wrap_controller, func):
""" Wrap calling to a function with a generator which needs to yield
exactly once. The yield point will trigger calling the wrapped function
and return its _CallOutcome to the yield point. The generator then needs
to finish (raise StopIteration) in order for the wrapped call to complete.
"""
try:
next(wrap_controller) # first yield
except StopIteration:
_raise_wrapfail(wrap_controller, "did not yield")
call_outcome = _CallOutcome(func)
try:
wrap_controller.send(call_outcome)
_raise_wrapfail(wrap_controller, "has second yield")
except StopIteration:
pass
> return call_outcome.get_result()
..\_pytest\vendored_packages\pluggy.py:253:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001d331619f60>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001d331619f60>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...sh_pointer'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>>
def __init__(self, func):
try:
> self.result = func()
..\_pytest\vendored_packages\pluggy.py:264:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_hash_pointer'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
return _wrapped_call(hook_impl.function(*args), self.execute)
> res = hook_impl.function(*args)
..\_pytest\vendored_packages\pluggy.py:596:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
item = <AppTestMethod 'test_hash_pointer'>
@pytest.hookimpl(tryfirst=True)
def pytest_runtest_setup(item):
if isinstance(item, pytest.Function):
config = item.config
if get_marker(item, name='pypy_only'):
if config.applevel is not None and not config.applevel.is_pypy:
pytest.skip('PyPy-specific test')
appclass = item.getparent(pytest.Class)
if appclass is not None:
from pypy.tool.pytest.objspace import gettestobjspace
# Make cls.space and cls.runappdirect available in tests.
spaceconfig = getattr(appclass.obj, 'spaceconfig', {})
> appclass.obj.space = gettestobjspace(**spaceconfig)
conftest.py:259:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]}
config = <rpython.config.config.Config object at 0x000001d3316842c0>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001d3316842c0>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001d3316842c0>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000001d3316842c0>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000001d330eff0a0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000001d330e51a28>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe499530a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49953060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49952ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000001d32c0def38>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x000001d331684838>, <W_TypeObject 'GenericAlias' at 0x1d32ea28ec8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32e5ac598>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32e5ac598>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32e5ac598>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32e5ac598>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32ce70f50>>
w_obj = <W_TypeObject 'ellipsis' at 0x1d32e5ac598>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x1d32e5ac598>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32ce70f50>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x1d32e5ac598>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32ce70f50>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32ce70f50>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32ce70f50>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'
..\rpython\rtyper\lltypesystem\lltype.py:1270: AttributeError
____________ ERROR at setup of AppTestCpythonExtension.test_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 0x000001d331fbbda8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=item, **kwds), when=when)
..\_pytest\runner.py:138:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_HookCaller 'pytest_runtest_setup'>
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_types'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_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 0x000001d327531440>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d32f2fcd60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001d3279f86a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d3279f86e0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_types'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_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 0x000001d32f2fcd60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001d3279f86a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d3279f86e0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_types'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_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_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 0x000001d32d7a87c8>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...test_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 0x000001d330c82220>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001d330c82220>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...test_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_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_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 = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]}
config = <rpython.config.config.Config object at 0x000001d330b68fe0>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001d330b68fe0>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001d330b68fe0>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000001d330b68fe0>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000001d330c835a0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000001d330e50250>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe499930a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49993060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49992ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000001d32c0def38>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x000001d330b69558>, <W_TypeObject 'GenericAlias' at 0x1d32eb436a8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32e5acd40>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32e5acd40>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32e5acd40>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32e5acd40>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32ce6f9f0>>
w_obj = <W_TypeObject 'ellipsis' at 0x1d32e5acd40>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x1d32e5acd40>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32ce6f9f0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x1d32e5acd40>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32ce6f9f0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32ce6f9f0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32ce6f9f0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'
..\rpython\rtyper\lltypesystem\lltype.py:1270: AttributeError
_______ ERROR at setup of AppTestCpythonExtension.test_get_programname ________
self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'>
func = <function <lambda> at 0x000001d3312832e0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=item, **kwds), when=when)
..\_pytest\runner.py:138:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_HookCaller 'pytest_runtest_setup'>
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_get_programname'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_get_programname'>}
def __call__(self, **kwargs):
assert not self.is_historic()
> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
..\_pytest\vendored_packages\pluggy.py:724:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.config.PytestPluginManager object at 0x000001d327531440>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d32f2fcd60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001d3279f86a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d3279f86e0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_get_programname'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_get_programname'>}
def _hookexec(self, hook, methods, kwargs):
# called from all hookcaller instances.
# enable_tracing will set its own wrapping function at self._inner_hookexec
> return self._inner_hookexec(hook, methods, kwargs)
..\_pytest\vendored_packages\pluggy.py:338:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d32f2fcd60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001d3279f86a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d3279f86e0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_get_programname'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_get_programname'>}
self._inner_hookexec = lambda hook, methods, kwargs: \
> _MultiCall(methods, kwargs, hook.spec_opts).execute()
..\_pytest\vendored_packages\pluggy.py:333:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_get_programname'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
> return _wrapped_call(hook_impl.function(*args), self.execute)
..\_pytest\vendored_packages\pluggy.py:595:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
wrap_controller = <generator object pytest_runtest_setup at 0x000001d32e204778>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...rogramname'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>>
def _wrapped_call(wrap_controller, func):
""" Wrap calling to a function with a generator which needs to yield
exactly once. The yield point will trigger calling the wrapped function
and return its _CallOutcome to the yield point. The generator then needs
to finish (raise StopIteration) in order for the wrapped call to complete.
"""
try:
next(wrap_controller) # first yield
except StopIteration:
_raise_wrapfail(wrap_controller, "did not yield")
call_outcome = _CallOutcome(func)
try:
wrap_controller.send(call_outcome)
_raise_wrapfail(wrap_controller, "has second yield")
except StopIteration:
pass
> return call_outcome.get_result()
..\_pytest\vendored_packages\pluggy.py:253:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001d3310cc4e0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001d3310cc4e0>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...rogramname'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>>
def __init__(self, func):
try:
> self.result = func()
..\_pytest\vendored_packages\pluggy.py:264:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_get_programname'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
return _wrapped_call(hook_impl.function(*args), self.execute)
> res = hook_impl.function(*args)
..\_pytest\vendored_packages\pluggy.py:596:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
item = <AppTestMethod 'test_get_programname'>
@pytest.hookimpl(tryfirst=True)
def pytest_runtest_setup(item):
if isinstance(item, pytest.Function):
config = item.config
if get_marker(item, name='pypy_only'):
if config.applevel is not None and not config.applevel.is_pypy:
pytest.skip('PyPy-specific test')
appclass = item.getparent(pytest.Class)
if appclass is not None:
from pypy.tool.pytest.objspace import gettestobjspace
# Make cls.space and cls.runappdirect available in tests.
spaceconfig = getattr(appclass.obj, 'spaceconfig', {})
> appclass.obj.space = gettestobjspace(**spaceconfig)
conftest.py:259:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]}
config = <rpython.config.config.Config object at 0x000001d33108edb0>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001d33108edb0>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001d33108edb0>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000001d33108edb0>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000001d3310cd7a0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000001d3316511a0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe499930a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49993060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49992ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000001d32c0def38>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x000001d33108f328>, <W_TypeObject 'GenericAlias' at 0x1d32e866608>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32e51dd70>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32e51dd70>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32e51dd70>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32e51dd70>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32ce71670>>
w_obj = <W_TypeObject 'ellipsis' at 0x1d32e51dd70>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x1d32e51dd70>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32ce71670>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x1d32e51dd70>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32ce71670>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32ce71670>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32ce71670>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'
..\rpython\rtyper\lltypesystem\lltype.py:1270: AttributeError
_________ ERROR at setup of AppTestCpythonExtension.test_get_version __________
self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'>
func = <function <lambda> at 0x000001d3318d9448>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=item, **kwds), when=when)
..\_pytest\runner.py:138:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_HookCaller 'pytest_runtest_setup'>
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_get_version'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_get_version'>}
def __call__(self, **kwargs):
assert not self.is_historic()
> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
..\_pytest\vendored_packages\pluggy.py:724:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.config.PytestPluginManager object at 0x000001d327531440>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d32f2fcd60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001d3279f86a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d3279f86e0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_get_version'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_get_version'>}
def _hookexec(self, hook, methods, kwargs):
# called from all hookcaller instances.
# enable_tracing will set its own wrapping function at self._inner_hookexec
> return self._inner_hookexec(hook, methods, kwargs)
..\_pytest\vendored_packages\pluggy.py:338:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d32f2fcd60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001d3279f86a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d3279f86e0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_get_version'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_get_version'>}
self._inner_hookexec = lambda hook, methods, kwargs: \
> _MultiCall(methods, kwargs, hook.spec_opts).execute()
..\_pytest\vendored_packages\pluggy.py:333:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_get_version'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
> return _wrapped_call(hook_impl.function(*args), self.execute)
..\_pytest\vendored_packages\pluggy.py:595:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
wrap_controller = <generator object pytest_runtest_setup at 0x000001d32aa52958>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...et_version'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>>
def _wrapped_call(wrap_controller, func):
""" Wrap calling to a function with a generator which needs to yield
exactly once. The yield point will trigger calling the wrapped function
and return its _CallOutcome to the yield point. The generator then needs
to finish (raise StopIteration) in order for the wrapped call to complete.
"""
try:
next(wrap_controller) # first yield
except StopIteration:
_raise_wrapfail(wrap_controller, "did not yield")
call_outcome = _CallOutcome(func)
try:
wrap_controller.send(call_outcome)
_raise_wrapfail(wrap_controller, "has second yield")
except StopIteration:
pass
> return call_outcome.get_result()
..\_pytest\vendored_packages\pluggy.py:253:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001d3322f0860>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001d3322f0860>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...et_version'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>>
def __init__(self, func):
try:
> self.result = func()
..\_pytest\vendored_packages\pluggy.py:264:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_get_version'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
return _wrapped_call(hook_impl.function(*args), self.execute)
> res = hook_impl.function(*args)
..\_pytest\vendored_packages\pluggy.py:596:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
item = <AppTestMethod 'test_get_version'>
@pytest.hookimpl(tryfirst=True)
def pytest_runtest_setup(item):
if isinstance(item, pytest.Function):
config = item.config
if get_marker(item, name='pypy_only'):
if config.applevel is not None and not config.applevel.is_pypy:
pytest.skip('PyPy-specific test')
appclass = item.getparent(pytest.Class)
if appclass is not None:
from pypy.tool.pytest.objspace import gettestobjspace
# Make cls.space and cls.runappdirect available in tests.
spaceconfig = getattr(appclass.obj, 'spaceconfig', {})
> appclass.obj.space = gettestobjspace(**spaceconfig)
conftest.py:259:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]}
config = <rpython.config.config.Config object at 0x000001d3322deb48>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001d3322deb48>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001d3322deb48>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000001d3322deb48>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000001d3322f1a20>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000001d3306213d0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe499530a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49953060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49952ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000001d32c0def38>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x000001d3322df0c0>, <W_TypeObject 'GenericAlias' at 0x1d32ed513d0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32e99d948>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32e99d948>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32e99d948>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32e99d948>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32ce712e0>>
w_obj = <W_TypeObject 'ellipsis' at 0x1d32e99d948>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x1d32e99d948>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32ce712e0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x1d32e99d948>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32ce712e0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32ce712e0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32ce712e0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'
..\rpython\rtyper\lltypesystem\lltype.py:1270: AttributeError
______ ERROR at setup of AppTestCpythonExtension.test_no_double_imports _______
self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'>
func = <function <lambda> at 0x000001d331cff9e8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=item, **kwds), when=when)
..\_pytest\runner.py:138:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_HookCaller 'pytest_runtest_setup'>
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_no_double_imports'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_no_double_imports'>}
def __call__(self, **kwargs):
assert not self.is_historic()
> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
..\_pytest\vendored_packages\pluggy.py:724:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.config.PytestPluginManager object at 0x000001d327531440>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d32f2fcd60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001d3279f86a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d3279f86e0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_no_double_imports'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_no_double_imports'>}
def _hookexec(self, hook, methods, kwargs):
# called from all hookcaller instances.
# enable_tracing will set its own wrapping function at self._inner_hookexec
> return self._inner_hookexec(hook, methods, kwargs)
..\_pytest\vendored_packages\pluggy.py:338:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d32f2fcd60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001d3279f86a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d3279f86e0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_no_double_imports'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_no_double_imports'>}
self._inner_hookexec = lambda hook, methods, kwargs: \
> _MultiCall(methods, kwargs, hook.spec_opts).execute()
..\_pytest\vendored_packages\pluggy.py:333:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_no_double_imports'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
> return _wrapped_call(hook_impl.function(*args), self.execute)
..\_pytest\vendored_packages\pluggy.py:595:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
wrap_controller = <generator object pytest_runtest_setup at 0x000001d332831e48>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...le_imports'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>>
def _wrapped_call(wrap_controller, func):
""" Wrap calling to a function with a generator which needs to yield
exactly once. The yield point will trigger calling the wrapped function
and return its _CallOutcome to the yield point. The generator then needs
to finish (raise StopIteration) in order for the wrapped call to complete.
"""
try:
next(wrap_controller) # first yield
except StopIteration:
_raise_wrapfail(wrap_controller, "did not yield")
call_outcome = _CallOutcome(func)
try:
wrap_controller.send(call_outcome)
_raise_wrapfail(wrap_controller, "has second yield")
except StopIteration:
pass
> return call_outcome.get_result()
..\_pytest\vendored_packages\pluggy.py:253:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001d3312a4aa0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001d3312a4aa0>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...le_imports'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>>
def __init__(self, func):
try:
> self.result = func()
..\_pytest\vendored_packages\pluggy.py:264:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_no_double_imports'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
return _wrapped_call(hook_impl.function(*args), self.execute)
> res = hook_impl.function(*args)
..\_pytest\vendored_packages\pluggy.py:596:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
item = <AppTestMethod 'test_no_double_imports'>
@pytest.hookimpl(tryfirst=True)
def pytest_runtest_setup(item):
if isinstance(item, pytest.Function):
config = item.config
if get_marker(item, name='pypy_only'):
if config.applevel is not None and not config.applevel.is_pypy:
pytest.skip('PyPy-specific test')
appclass = item.getparent(pytest.Class)
if appclass is not None:
from pypy.tool.pytest.objspace import gettestobjspace
# Make cls.space and cls.runappdirect available in tests.
spaceconfig = getattr(appclass.obj, 'spaceconfig', {})
> appclass.obj.space = gettestobjspace(**spaceconfig)
conftest.py:259:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]}
config = <rpython.config.config.Config object at 0x000001d3312da288>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001d3312da288>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001d3312da288>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000001d3312da288>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000001d3312a5ea0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000001d32e565638>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe499530a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49953060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49952ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000001d32c0def38>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x000001d3312da800>, <W_TypeObject 'GenericAlias' at 0x1d32ee01718>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32e7f6e58>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32e7f6e58>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32e7f6e58>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32e7f6e58>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32ce70830>>
w_obj = <W_TypeObject 'ellipsis' at 0x1d32e7f6e58>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x1d32e7f6e58>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32ce70830>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x1d32e7f6e58>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32ce70830>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32ce70830>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32ce70830>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'
..\rpython\rtyper\lltypesystem\lltype.py:1270: AttributeError
_______ ERROR at setup of AppTestCpythonExtension.test_no_structmember ________
self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'>
func = <function <lambda> at 0x000001d32e0ac548>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=item, **kwds), when=when)
..\_pytest\runner.py:138:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_HookCaller 'pytest_runtest_setup'>
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_no_structmember'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_no_structmember'>}
def __call__(self, **kwargs):
assert not self.is_historic()
> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
..\_pytest\vendored_packages\pluggy.py:724:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.config.PytestPluginManager object at 0x000001d327531440>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d32f2fcd60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001d3279f86a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d3279f86e0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_no_structmember'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_no_structmember'>}
def _hookexec(self, hook, methods, kwargs):
# called from all hookcaller instances.
# enable_tracing will set its own wrapping function at self._inner_hookexec
> return self._inner_hookexec(hook, methods, kwargs)
..\_pytest\vendored_packages\pluggy.py:338:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d32f2fcd60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001d3279f86a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d3279f86e0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_no_structmember'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_no_structmember'>}
self._inner_hookexec = lambda hook, methods, kwargs: \
> _MultiCall(methods, kwargs, hook.spec_opts).execute()
..\_pytest\vendored_packages\pluggy.py:333:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_no_structmember'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
> return _wrapped_call(hook_impl.function(*args), self.execute)
..\_pytest\vendored_packages\pluggy.py:595:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
wrap_controller = <generator object pytest_runtest_setup at 0x000001d32d604e80>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ructmember'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>>
def _wrapped_call(wrap_controller, func):
""" Wrap calling to a function with a generator which needs to yield
exactly once. The yield point will trigger calling the wrapped function
and return its _CallOutcome to the yield point. The generator then needs
to finish (raise StopIteration) in order for the wrapped call to complete.
"""
try:
next(wrap_controller) # first yield
except StopIteration:
_raise_wrapfail(wrap_controller, "did not yield")
call_outcome = _CallOutcome(func)
try:
wrap_controller.send(call_outcome)
_raise_wrapfail(wrap_controller, "has second yield")
except StopIteration:
pass
> return call_outcome.get_result()
..\_pytest\vendored_packages\pluggy.py:253:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001d33233f360>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001d33233f360>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ructmember'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>>
def __init__(self, func):
try:
> self.result = func()
..\_pytest\vendored_packages\pluggy.py:264:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_no_structmember'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
return _wrapped_call(hook_impl.function(*args), self.execute)
> res = hook_impl.function(*args)
..\_pytest\vendored_packages\pluggy.py:596:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
item = <AppTestMethod 'test_no_structmember'>
@pytest.hookimpl(tryfirst=True)
def pytest_runtest_setup(item):
if isinstance(item, pytest.Function):
config = item.config
if get_marker(item, name='pypy_only'):
if config.applevel is not None and not config.applevel.is_pypy:
pytest.skip('PyPy-specific test')
appclass = item.getparent(pytest.Class)
if appclass is not None:
from pypy.tool.pytest.objspace import gettestobjspace
# Make cls.space and cls.runappdirect available in tests.
spaceconfig = getattr(appclass.obj, 'spaceconfig', {})
> appclass.obj.space = gettestobjspace(**spaceconfig)
conftest.py:259:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]}
config = <rpython.config.config.Config object at 0x000001d331155638>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001d331155638>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001d331155638>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000001d331155638>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000001d33141a6a0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000001d32ec1c330>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe499930a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49993060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49992ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000001d32c0def38>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x000001d331155bb0>, <W_TypeObject 'GenericAlias' at 0x1d32eed3210>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32e9ad1d8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32e9ad1d8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32e9ad1d8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32e9ad1d8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32ce6f660>>
w_obj = <W_TypeObject 'ellipsis' at 0x1d32e9ad1d8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x1d32e9ad1d8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32ce6f660>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x1d32e9ad1d8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32ce6f660>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32ce6f660>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32ce6f660>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'
..\rpython\rtyper\lltypesystem\lltype.py:1270: AttributeError
_______ ERROR at setup of AppTestCpythonExtension.test_consistent_flags _______
self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'>
func = <function <lambda> at 0x000001d3305f15b0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=item, **kwds), when=when)
..\_pytest\runner.py:138:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_HookCaller 'pytest_runtest_setup'>
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_consistent_flags'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_consistent_flags'>}
def __call__(self, **kwargs):
assert not self.is_historic()
> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
..\_pytest\vendored_packages\pluggy.py:724:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.config.PytestPluginManager object at 0x000001d327531440>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d32f2fcd60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001d3279f86a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d3279f86e0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_consistent_flags'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_consistent_flags'>}
def _hookexec(self, hook, methods, kwargs):
# called from all hookcaller instances.
# enable_tracing will set its own wrapping function at self._inner_hookexec
> return self._inner_hookexec(hook, methods, kwargs)
..\_pytest\vendored_packages\pluggy.py:338:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d32f2fcd60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001d3279f86a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d3279f86e0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_consistent_flags'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_consistent_flags'>}
self._inner_hookexec = lambda hook, methods, kwargs: \
> _MultiCall(methods, kwargs, hook.spec_opts).execute()
..\_pytest\vendored_packages\pluggy.py:333:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_consistent_flags'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
> return _wrapped_call(hook_impl.function(*args), self.execute)
..\_pytest\vendored_packages\pluggy.py:595:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
wrap_controller = <generator object pytest_runtest_setup at 0x000001d32e1f7970>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...tent_flags'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>>
def _wrapped_call(wrap_controller, func):
""" Wrap calling to a function with a generator which needs to yield
exactly once. The yield point will trigger calling the wrapped function
and return its _CallOutcome to the yield point. The generator then needs
to finish (raise StopIteration) in order for the wrapped call to complete.
"""
try:
next(wrap_controller) # first yield
except StopIteration:
_raise_wrapfail(wrap_controller, "did not yield")
call_outcome = _CallOutcome(func)
try:
wrap_controller.send(call_outcome)
_raise_wrapfail(wrap_controller, "has second yield")
except StopIteration:
pass
> return call_outcome.get_result()
..\_pytest\vendored_packages\pluggy.py:253:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001d331813a20>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001d331813a20>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...tent_flags'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>>
def __init__(self, func):
try:
> self.result = func()
..\_pytest\vendored_packages\pluggy.py:264:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_consistent_flags'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
return _wrapped_call(hook_impl.function(*args), self.execute)
> res = hook_impl.function(*args)
..\_pytest\vendored_packages\pluggy.py:596:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
item = <AppTestMethod 'test_consistent_flags'>
@pytest.hookimpl(tryfirst=True)
def pytest_runtest_setup(item):
if isinstance(item, pytest.Function):
config = item.config
if get_marker(item, name='pypy_only'):
if config.applevel is not None and not config.applevel.is_pypy:
pytest.skip('PyPy-specific test')
appclass = item.getparent(pytest.Class)
if appclass is not None:
from pypy.tool.pytest.objspace import gettestobjspace
# Make cls.space and cls.runappdirect available in tests.
spaceconfig = getattr(appclass.obj, 'spaceconfig', {})
> appclass.obj.space = gettestobjspace(**spaceconfig)
conftest.py:259:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]}
config = <rpython.config.config.Config object at 0x000001d331939398>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001d331939398>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001d331939398>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000001d331939398>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000001d331faaba0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000001d32e8af718>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe499930a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49993060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49992ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000001d32c0def38>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x000001d331939910>, <W_TypeObject 'GenericAlias' at 0x1d32ef26138>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32e867830>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32e867830>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32e867830>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32e867830>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32ce71d90>>
w_obj = <W_TypeObject 'ellipsis' at 0x1d32e867830>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x1d32e867830>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32ce71d90>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x1d32e867830>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32ce71d90>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32ce71d90>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32ce71d90>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'
..\rpython\rtyper\lltypesystem\lltype.py:1270: AttributeError
_________ ERROR at setup of AppTestCpythonExtension.test_generic_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 0x000001d331023da8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=item, **kwds), when=when)
..\_pytest\runner.py:138:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_HookCaller 'pytest_runtest_setup'>
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_generic_type'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_generic_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 0x000001d327531440>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d32f2fcd60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001d3279f86a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d3279f86e0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_generic_type'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_generic_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 0x000001d32f2fcd60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001d3279f86a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001d3279f86e0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_generic_type'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_generic_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_generic_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 0x000001d32c43c200>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...neric_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 0x000001d331968220>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001d331968220>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...neric_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_generic_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_generic_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 0x000001d33192a9f8>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001d33192a9f8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001d33192a9f8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000001d33192a9f8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000001d33125bda0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000001d330f66480>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe499930a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49993060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49992ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000001d32c0def38>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x000001d33192af70>, <W_TypeObject 'GenericAlias' at 0x1d32eed2b80>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32e8402f8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32e8402f8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32e8402f8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d32e8402f8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32ce72120>>
w_obj = <W_TypeObject 'ellipsis' at 0x1d32e8402f8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x1d32e8402f8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32ce72120>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x1d32e8402f8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32ce72120>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32ce72120>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d32ce72120>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E 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 passed, 25 error in 861.07 seconds =====================
++ 06:29:37 starting module/cpyext/test/test_exception.py [63 started in total]
__ module/cpyext/test/test_dictobject.py [60 done in total, somefailed=True] __
[platform:msg] Updated environment with vsver 160, using x64 True
[platform:msg] Updated environment with vsver 160, using x64 True
============================= test session starts =============================
platform win32 -- Python 2.7.18[pypy-7.3.18-alpha], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('d:\\pypy_stuff\\buildbot64\\slave\\own-win-x86-64\\build\\pypy\\.hypothesis\\examples')
pytest-2.9.2 from d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pytest.pyc
rootdir: d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 19 items
module\cpyext\test\test_dictobject.py EEEEEEEEEEEEEEEEEEE
=================================== ERRORS ====================================
_________________ ERROR at setup of TestDictObject.test_dict __________________
item = <Function 'test_dict'>
@pytest.hookimpl(tryfirst=True)
def pytest_runtest_setup(item):
if isinstance(item, pytest.Function):
config = item.config
if get_marker(item, name='pypy_only'):
if config.applevel is not None and not config.applevel.is_pypy:
pytest.skip('PyPy-specific test')
appclass = item.getparent(pytest.Class)
if appclass is not None:
from pypy.tool.pytest.objspace import gettestobjspace
# Make cls.space and cls.runappdirect available in tests.
spaceconfig = getattr(appclass.obj, 'spaceconfig', {})
> appclass.obj.space = gettestobjspace(**spaceconfig)
conftest.py:259:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
tool\pytest\objspace.py:24: in gettestobjspace
space = maketestobjspace(config)
tool\pytest\objspace.py:34: in maketestobjspace
space = make_objspace(config)
tool\option.py:33: in make_objspace
return StdObjSpace(config)
interpreter\baseobjspace.py:481: in __init__
self.initialize()
objspace\std\objspace.py:118: in initialize
self.setup_builtin_modules()
interpreter\baseobjspace.py:739: in setup_builtin_modules
self.fromcache(State).build_api()
module\cpyext\state.py:128: in build_api
self.api_lib = str(api.build_bridge(self.space))
module\cpyext\api.py:1468: in build_bridge
builder.attach_all(space)
module\cpyext\api.py:1535: in attach_all
attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1497: in attach_recursively
make_ref(space, w_type))
module\cpyext\pyobject.py:510: in make_ref
return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:483: in get_pyobj_and_incref
pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445: in as_pyobj
py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:326: in create_ref
track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:375: in track_reference
w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:132: in _cpyext_attach_pyobj
rawrefcount.create_link_pypy(self, py_obj)
..\rpython\rlib\rawrefcount.py:187: in create_link_pypy
assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:102: in _ob_link_get
return ob.c_ob_pypy_link
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b289ec10b0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x1b289ec29a0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x1b289ec1440>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x1b289ec2280>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x1b289ec0d20>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x1b289ec2610>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x1b289ec30c0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x1b289ec3f00>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x000001b28de6aa70>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x000001b2881c1440>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001b2893ba060>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001b2886866a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001b2886866e0>]
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 0x000001b2893ba060>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001b2886866a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001b2886866e0>]
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 0x000001b28febf448>
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 0x000001b291f4fa60>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001b291f4fa60>
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 0x000001b291ba08e0>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001b291ba08e0>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001b291ba08e0>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000001b291ba08e0>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000001b292b7d120>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000001b28b35e4b8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe499540a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49954060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49953ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000001b28cb852b8>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x000001b291ba0e58>, <W_TypeObject 'GenericAlias' at 0x1b28f3a49c0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b28ee2ac60>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b28ee2ac60>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b28ee2ac60>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b28ee2ac60>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b289ec3b70>>
w_obj = <W_TypeObject 'ellipsis' at 0x1b28ee2ac60>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x1b28ee2ac60>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b289ec3b70>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x1b28ee2ac60>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b289ec3b70>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b289ec3b70>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b289ec3b70>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x000001b28917f448>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x000001b2881c1440>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001b2893ba060>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001b2886866a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001b2886866e0>]
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 0x000001b2893ba060>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001b2886866a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001b2886866e0>]
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 0x000001b28ef849d0>
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 0x000001b29066e220>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001b29066e220>
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 0x000001b2922fec28>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001b2922fec28>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001b2922fec28>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000001b2922fec28>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000001b29066f5a0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000001b28f2b63a0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe499940a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49994060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49993ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000001b28cb852b8>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x000001b2922ff1a0>, <W_TypeObject 'GenericAlias' at 0x1b28f41f910>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b28f26fa28>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b28f26fa28>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b28f26fa28>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b28f26fa28>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b289ec4290>>
w_obj = <W_TypeObject 'ellipsis' at 0x1b28f26fa28>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x1b28f26fa28>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b289ec4290>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x1b28f26fa28>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b289ec4290>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b289ec4290>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b289ec4290>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x000001b28de6aa70>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x000001b2881c1440>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001b2893ba060>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001b2886866a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001b2886866e0>]
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 0x000001b2893ba060>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001b2886866a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001b2886866e0>]
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 0x000001b28d1f4e80>
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 0x000001b292a3cb20>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001b292a3cb20>
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 0x000001b291334598>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001b291334598>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001b291334598>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000001b291334598>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000001b292a3dce0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000001b28f20ef38>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe499540a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49954060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49953ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000001b28cb852b8>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x000001b291334b10>, <W_TypeObject 'GenericAlias' at 0x1b28f441590>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b28f1d60c8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b28f1d60c8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b28f1d60c8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b28f1d60c8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b28d36da10>>
w_obj = <W_TypeObject 'ellipsis' at 0x1b28f1d60c8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x1b28f1d60c8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b28d36da10>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x1b28f1d60c8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b28d36da10>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b28d36da10>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b28d36da10>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x000001b29216b5b0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x000001b2881c1440>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001b2893ba060>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001b2886866a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001b2886866e0>]
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 0x000001b2893ba060>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001b2886866a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001b2886866e0>]
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 0x000001b288aa1880>
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 0x000001b292a6d820>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001b292a6d820>
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 0x000001b291990aa0>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001b291990aa0>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001b291990aa0>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000001b291990aa0>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000001b291e36960>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000001b28922c678>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe499540a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49954060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49953ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000001b28cb852b8>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x000001b291991018>, <W_TypeObject 'GenericAlias' at 0x1b28f441478>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b28f1b6790>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b28f1b6790>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b28f1b6790>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b28f1b6790>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b28d36c120>>
w_obj = <W_TypeObject 'ellipsis' at 0x1b28f1b6790>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x1b28f1b6790>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b28d36c120>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x1b28f1b6790>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b28d36c120>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b28d36c120>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b28d36c120>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x000001b290229d30>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x000001b2881c1440>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001b2893ba060>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001b2886866a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001b2886866e0>]
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 0x000001b2893ba060>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001b2886866a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001b2886866e0>]
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 0x000001b28db75e70>
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 0x000001b292c815e0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001b292c815e0>
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 0x000001b292c76d78>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001b292c76d78>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001b292c76d78>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000001b292c76d78>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000001b2905d6720>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000001b28a3afc58>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe499940a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49994060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49993ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000001b28cb852b8>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x000001b292c772f0>, <W_TypeObject 'GenericAlias' at 0x1b28f44c218>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b28f26fb08>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b28f26fb08>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b28f26fb08>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b28f26fb08>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b28d36b2e0>>
w_obj = <W_TypeObject 'ellipsis' at 0x1b28f26fb08>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x1b28f26fb08>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b28d36b2e0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x1b28f26fb08>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b28d36b2e0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b28d36b2e0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b28d36b2e0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x000001b293265880>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x000001b2881c1440>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001b2893ba060>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001b2886866a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001b2886866e0>]
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 0x000001b2893ba060>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001b2886866a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001b2886866e0>]
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 0x000001b28cfa1a38>
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 0x000001b2915f6ea0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001b2915f6ea0>
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 0x000001b291cc6598>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001b291cc6598>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001b291cc6598>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000001b291cc6598>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000001b2907180e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000001b28f0ff8a0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe499940a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49994060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49993ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000001b28cb852b8>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x000001b291cc6b10>, <W_TypeObject 'GenericAlias' at 0x1b28f37d210>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b28f1d6db0>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b28f1d6db0>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b28f1d6db0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b28f1d6db0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b28d36d680>>
w_obj = <W_TypeObject 'ellipsis' at 0x1b28f1d6db0>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x1b28f1d6db0>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b28d36d680>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x1b28f1d6db0>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b28d36d680>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b28d36d680>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b28d36d680>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x000001b292ed8980>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x000001b2881c1440>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001b2893ba060>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001b2886866a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001b2886866e0>]
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 0x000001b2893ba060>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001b2886866a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001b2886866e0>]
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 0x000001b28fb11240>
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 0x000001b290560ca0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001b290560ca0>
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 0x000001b29057bb78>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001b29057bb78>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001b29057bb78>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000001b29057bb78>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000001b290561e60>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000001b28f3a57c0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe499940a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49994060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49993ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000001b28cb852b8>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x000001b2925797c0>, <W_TypeObject 'GenericAlias' at 0x1b28f544678>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b28f3e4a68>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b28f3e4a68>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b28f3e4a68>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b28f3e4a68>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b28d36ba00>>
w_obj = <W_TypeObject 'ellipsis' at 0x1b28f3e4a68>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x1b28f3e4a68>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b28d36ba00>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x1b28f3e4a68>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b28d36ba00>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b28d36ba00>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b28d36ba00>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x000001b29216a2f0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x000001b2881c1440>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001b2893ba060>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001b2886866a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001b2886866e0>]
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 0x000001b2893ba060>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001b2886866a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001b2886866e0>]
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 0x000001b28ea7ec28>
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 0x000001b2905e6920>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001b2905e6920>
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 0x000001b291d94410>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001b291d94410>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001b291d94410>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000001b291d94410>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000001b291db09e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000001b28f21fbb0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe499940a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49994060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49993ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000001b28cb852b8>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x000001b291d94988>, <W_TypeObject 'GenericAlias' at 0x1b28f4d1cc8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b28f24c988>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b28f24c988>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b28f24c988>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b28f24c988>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b28d36b670>>
w_obj = <W_TypeObject 'ellipsis' at 0x1b28f24c988>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x1b28f24c988>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b28d36b670>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x1b28f24c988>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b28d36b670>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b28d36b670>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b28d36b670>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x000001b2911942f0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x000001b2881c1440>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001b2893ba060>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001b2886866a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001b2886866e0>]
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 0x000001b2893ba060>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001b2886866a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001b2886866e0>]
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 0x000001b28d254b60>
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 0x000001b2905e1060>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001b2905e1060>
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 0x000001b292a874e8>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001b292a874e8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001b292a874e8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000001b292a874e8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000001b291e2c260>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000001b2919132b8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe499940a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49994060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49993ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000001b28cb852b8>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x000001b292a87a60>, <W_TypeObject 'GenericAlias' at 0x1b28f4d0870>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b28f233168>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b28f233168>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b28f233168>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b28f233168>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b28d36dda0>>
w_obj = <W_TypeObject 'ellipsis' at 0x1b28f233168>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x1b28f233168>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b28d36dda0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x1b28f233168>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b28d36dda0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b28d36dda0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b28d36dda0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x000001b28fb33970>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x000001b2881c1440>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001b2893ba060>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001b2886866a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001b2886866e0>]
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 0x000001b2893ba060>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001b2886866a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001b2886866e0>]
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 0x000001b28fb10958>
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 0x000001b2906f1a60>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001b2906f1a60>
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 0x000001b2905dd600>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001b2905dd600>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001b2905dd600>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000001b2905dd600>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000001b291ae5420>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000001b28f377130>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe499540a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49954060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49953ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000001b28cb852b8>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x000001b291b2ef00>, <W_TypeObject 'GenericAlias' at 0x1b28f5e7a60>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b28f2c4800>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b28f2c4800>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b28f2c4800>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b28f2c4800>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b28d36c4b0>>
w_obj = <W_TypeObject 'ellipsis' at 0x1b28f2c4800>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x1b28f2c4800>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b28d36c4b0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x1b28f2c4800>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b28d36c4b0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b28d36c4b0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b28d36c4b0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x000001b292ed8278>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=item, **kwds), when=when)
..\_pytest\runner.py:138:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_HookCaller 'pytest_runtest_setup'>
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_contains'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_contains'>}
def __call__(self, **kwargs):
assert not self.is_historic()
> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
..\_pytest\vendored_packages\pluggy.py:724:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.config.PytestPluginManager object at 0x000001b2881c1440>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001b2893ba060>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001b2886866a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001b2886866e0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_contains'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_contains'>}
def _hookexec(self, hook, methods, kwargs):
# called from all hookcaller instances.
# enable_tracing will set its own wrapping function at self._inner_hookexec
> return self._inner_hookexec(hook, methods, kwargs)
..\_pytest\vendored_packages\pluggy.py:338:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001b2893ba060>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001b2886866a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001b2886866e0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_contains'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_contains'>}
self._inner_hookexec = lambda hook, methods, kwargs: \
> _MultiCall(methods, kwargs, hook.spec_opts).execute()
..\_pytest\vendored_packages\pluggy.py:333:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_contains'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
> return _wrapped_call(hook_impl.function(*args), self.execute)
..\_pytest\vendored_packages\pluggy.py:595:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
wrap_controller = <generator object pytest_runtest_setup at 0x000001b28f187218>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...t_contains'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>>
def _wrapped_call(wrap_controller, func):
""" Wrap calling to a function with a generator which needs to yield
exactly once. The yield point will trigger calling the wrapped function
and return its _CallOutcome to the yield point. The generator then needs
to finish (raise StopIteration) in order for the wrapped call to complete.
"""
try:
next(wrap_controller) # first yield
except StopIteration:
_raise_wrapfail(wrap_controller, "did not yield")
call_outcome = _CallOutcome(func)
try:
wrap_controller.send(call_outcome)
_raise_wrapfail(wrap_controller, "has second yield")
except StopIteration:
pass
> return call_outcome.get_result()
..\_pytest\vendored_packages\pluggy.py:253:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001b29059baa0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001b29059baa0>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...t_contains'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>>
def __init__(self, func):
try:
> self.result = func()
..\_pytest\vendored_packages\pluggy.py:264:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_contains'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
return _wrapped_call(hook_impl.function(*args), self.execute)
> res = hook_impl.function(*args)
..\_pytest\vendored_packages\pluggy.py:596:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
item = <AppTestMethod 'test_contains'>
@pytest.hookimpl(tryfirst=True)
def pytest_runtest_setup(item):
if isinstance(item, pytest.Function):
config = item.config
if get_marker(item, name='pypy_only'):
if config.applevel is not None and not config.applevel.is_pypy:
pytest.skip('PyPy-specific test')
appclass = item.getparent(pytest.Class)
if appclass is not None:
from pypy.tool.pytest.objspace import gettestobjspace
# Make cls.space and cls.runappdirect available in tests.
spaceconfig = getattr(appclass.obj, 'spaceconfig', {})
> appclass.obj.space = gettestobjspace(**spaceconfig)
conftest.py:259:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]}
config = <rpython.config.config.Config object at 0x000001b290534e20>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001b290534e20>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001b290534e20>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000001b290534e20>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000001b29155ce60>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000001b291e1c1a8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe498e40a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe498e4060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe498e3ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000001b28cb852b8>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x000001b290535440>, <W_TypeObject 'GenericAlias' at 0x1b28f5972f0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b28f2c5b08>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b28f2c5b08>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b28f2c5b08>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b28f2c5b08>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b28d36c840>>
w_obj = <W_TypeObject 'ellipsis' at 0x1b28f2c5b08>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x1b28f2c5b08>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b28d36c840>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x1b28f2c5b08>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b28d36c840>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b28d36c840>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b28d36c840>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'
..\rpython\rtyper\lltypesystem\lltype.py:1270: AttributeError
========================= 19 error in 659.04 seconds ==========================
++ 06:30:54 starting module/cpyext/test/test_fileobject.py [64 started in total]
__ module/cpyext/test/test_fileobject.py [61 done in total, somefailed=True] __
[platform:msg] Updated environment with vsver 160, using x64 True
[platform:msg] Updated environment with vsver 160, using x64 True
============================= test session starts =============================
platform win32 -- Python 2.7.18[pypy-7.3.18-alpha], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('d:\\pypy_stuff\\buildbot64\\slave\\own-win-x86-64\\build\\pypy\\.hypothesis\\examples')
pytest-2.9.2 from d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pytest.pyc
rootdir: d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 1 items
module\cpyext\test\test_fileobject.py E
=================================== ERRORS ====================================
__________ ERROR at setup of AppTestFileObject.test_defaultencoding ___________
self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'>
func = <function <lambda> at 0x000002bb33aba278>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=item, **kwds), when=when)
..\_pytest\runner.py:138:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_HookCaller 'pytest_runtest_setup'>
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_defaultencoding'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_defaultencoding'>}
def __call__(self, **kwargs):
assert not self.is_historic()
> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
..\_pytest\vendored_packages\pluggy.py:724:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.config.PytestPluginManager object at 0x000002bb2b991440>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000002bb333945a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000002bb2be566a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000002bb2be566e0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_defaultencoding'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_defaultencoding'>}
def _hookexec(self, hook, methods, kwargs):
# called from all hookcaller instances.
# enable_tracing will set its own wrapping function at self._inner_hookexec
> return self._inner_hookexec(hook, methods, kwargs)
..\_pytest\vendored_packages\pluggy.py:338:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000002bb333945a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000002bb2be566a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000002bb2be566e0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_defaultencoding'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_defaultencoding'>}
self._inner_hookexec = lambda hook, methods, kwargs: \
> _MultiCall(methods, kwargs, hook.spec_opts).execute()
..\_pytest\vendored_packages\pluggy.py:333:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_defaultencoding'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
> return _wrapped_call(hook_impl.function(*args), self.execute)
..\_pytest\vendored_packages\pluggy.py:595:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
wrap_controller = <generator object pytest_runtest_setup at 0x000002bb3158ac28>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ltencoding'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>>
def _wrapped_call(wrap_controller, func):
""" Wrap calling to a function with a generator which needs to yield
exactly once. The yield point will trigger calling the wrapped function
and return its _CallOutcome to the yield point. The generator then needs
to finish (raise StopIteration) in order for the wrapped call to complete.
"""
try:
next(wrap_controller) # first yield
except StopIteration:
_raise_wrapfail(wrap_controller, "did not yield")
call_outcome = _CallOutcome(func)
try:
wrap_controller.send(call_outcome)
_raise_wrapfail(wrap_controller, "has second yield")
except StopIteration:
pass
> return call_outcome.get_result()
..\_pytest\vendored_packages\pluggy.py:253:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000002bb32a86760>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000002bb32a86760>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ltencoding'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>>
def __init__(self, func):
try:
> self.result = func()
..\_pytest\vendored_packages\pluggy.py:264:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_defaultencoding'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
return _wrapped_call(hook_impl.function(*args), self.execute)
> res = hook_impl.function(*args)
..\_pytest\vendored_packages\pluggy.py:596:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
item = <AppTestMethod 'test_defaultencoding'>
@pytest.hookimpl(tryfirst=True)
def pytest_runtest_setup(item):
if isinstance(item, pytest.Function):
config = item.config
if get_marker(item, name='pypy_only'):
if config.applevel is not None and not config.applevel.is_pypy:
pytest.skip('PyPy-specific test')
appclass = item.getparent(pytest.Class)
if appclass is not None:
from pypy.tool.pytest.objspace import gettestobjspace
# Make cls.space and cls.runappdirect available in tests.
spaceconfig = getattr(appclass.obj, 'spaceconfig', {})
> appclass.obj.space = gettestobjspace(**spaceconfig)
conftest.py:259:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]}
config = <rpython.config.config.Config object at 0x000002bb3239bec0>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000002bb3239bec0>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000002bb3239bec0>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000002bb3239bec0>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000002bb32a87660>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000002bb32cb8c98>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe499930a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49993060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49992ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000002bb2ef614b0>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x000002bb32366288>, <W_TypeObject 'GenericAlias' at 0x2bb33635d38>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2bb33dc8de8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2bb33dc8de8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2bb33dc8de8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2bb33dc8de8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2bb31393890>>
w_obj = <W_TypeObject 'ellipsis' at 0x2bb33dc8de8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x2bb33dc8de8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2bb31393890>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x2bb33dc8de8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2bb31393890>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2bb31393890>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2bb31393890>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E 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 44.39 seconds ===========================
++ 06:32:22 starting module/cpyext/test/test_floatobject.py [65 started in total]
__ module/cpyext/test/test_exception.py [62 done in total, somefailed=True] ___
[platform:msg] Updated environment with vsver 160, using x64 True
[platform:msg] Updated environment with vsver 160, using x64 True
============================= test session starts =============================
platform win32 -- Python 2.7.18[pypy-7.3.18-alpha], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('d:\\pypy_stuff\\buildbot64\\slave\\own-win-x86-64\\build\\pypy\\.hypothesis\\examples')
pytest-2.9.2 from d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pytest.pyc
rootdir: d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 8 items
module\cpyext\test\test_exception.py EEEEEEEE
=================================== ERRORS ====================================
________ ERROR at setup of TestExceptions.test_ExceptionInstance_Class ________
item = <Function 'test_ExceptionInstance_Class'>
@pytest.hookimpl(tryfirst=True)
def pytest_runtest_setup(item):
if isinstance(item, pytest.Function):
config = item.config
if get_marker(item, name='pypy_only'):
if config.applevel is not None and not config.applevel.is_pypy:
pytest.skip('PyPy-specific test')
appclass = item.getparent(pytest.Class)
if appclass is not None:
from pypy.tool.pytest.objspace 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 0x16ef8db2790>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'
..\rpython\rtyper\lltypesystem\lltype.py:1270: AttributeError
_______________ ERROR at setup of TestExceptions.test_traceback _______________
item = <Function 'test_traceback'>
@pytest.hookimpl(tryfirst=True)
def pytest_runtest_setup(item):
if isinstance(item, pytest.Function):
config = item.config
if get_marker(item, name='pypy_only'):
if config.applevel is not None and not config.applevel.is_pypy:
pytest.skip('PyPy-specific test')
appclass = item.getparent(pytest.Class)
if appclass is not None:
from pypy.tool.pytest.objspace 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 0x16ef8db0ea0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'
..\rpython\rtyper\lltypesystem\lltype.py:1270: AttributeError
________________ ERROR at setup of TestExceptions.test_context ________________
item = <Function '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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
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 0x16ef8db15c0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'
..\rpython\rtyper\lltypesystem\lltype.py:1270: AttributeError
_________________ ERROR at setup of TestExceptions.test_cause _________________
item = <Function 'test_cause'>
@pytest.hookimpl(tryfirst=True)
def pytest_runtest_setup(item):
if isinstance(item, pytest.Function):
config = item.config
if get_marker(item, name='pypy_only'):
if config.applevel is not None and not config.applevel.is_pypy:
pytest.skip('PyPy-specific test')
appclass = item.getparent(pytest.Class)
if appclass is not None:
from pypy.tool.pytest.objspace 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 0x16ef8db1230>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'
..\rpython\rtyper\lltypesystem\lltype.py:1270: AttributeError
_________________ ERROR at setup of TestExceptions.test_args __________________
item = <Function 'test_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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
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 0x16ef8db2070>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'
..\rpython\rtyper\lltypesystem\lltype.py:1270: AttributeError
__________ ERROR at setup of AppTestExceptions.test_OSError_aliases ___________
self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'>
func = <function <lambda> at 0x0000016efe83be98>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=item, **kwds), when=when)
..\_pytest\runner.py:138:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_HookCaller 'pytest_runtest_setup'>
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_OSError_aliases'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_OSError_aliases'>}
def __call__(self, **kwargs):
assert not self.is_historic()
> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
..\_pytest\vendored_packages\pluggy.py:724:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.config.PytestPluginManager object at 0x0000016ef37b1440>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000016efb453ba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000016ef3c766a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000016ef3c766e0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_OSError_aliases'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_OSError_aliases'>}
def _hookexec(self, hook, methods, kwargs):
# called from all hookcaller instances.
# enable_tracing will set its own wrapping function at self._inner_hookexec
> return self._inner_hookexec(hook, methods, kwargs)
..\_pytest\vendored_packages\pluggy.py:338:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000016efb453ba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000016ef3c766a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000016ef3c766e0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_OSError_aliases'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_OSError_aliases'>}
self._inner_hookexec = lambda hook, methods, kwargs: \
> _MultiCall(methods, kwargs, hook.spec_opts).execute()
..\_pytest\vendored_packages\pluggy.py:333:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_OSError_aliases'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
> return _wrapped_call(hook_impl.function(*args), self.execute)
..\_pytest\vendored_packages\pluggy.py:595:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
wrap_controller = <generator object pytest_runtest_setup at 0x0000016efba683e0>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...or_aliases'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>>
def _wrapped_call(wrap_controller, func):
""" Wrap calling to a function with a generator which needs to yield
exactly once. The yield point will trigger calling the wrapped function
and return its _CallOutcome to the yield point. The generator then needs
to finish (raise StopIteration) in order for the wrapped call to complete.
"""
try:
next(wrap_controller) # first yield
except StopIteration:
_raise_wrapfail(wrap_controller, "did not yield")
call_outcome = _CallOutcome(func)
try:
wrap_controller.send(call_outcome)
_raise_wrapfail(wrap_controller, "has second yield")
except StopIteration:
pass
> return call_outcome.get_result()
..\_pytest\vendored_packages\pluggy.py:253:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000016efca08f60>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000016efca08f60>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...or_aliases'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>>
def __init__(self, func):
try:
> self.result = func()
..\_pytest\vendored_packages\pluggy.py:264:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_OSError_aliases'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
return _wrapped_call(hook_impl.function(*args), self.execute)
> res = hook_impl.function(*args)
..\_pytest\vendored_packages\pluggy.py:596:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
item = <AppTestMethod 'test_OSError_aliases'>
@pytest.hookimpl(tryfirst=True)
def pytest_runtest_setup(item):
if isinstance(item, pytest.Function):
config = item.config
if get_marker(item, name='pypy_only'):
if config.applevel is not None and not config.applevel.is_pypy:
pytest.skip('PyPy-specific test')
appclass = item.getparent(pytest.Class)
if appclass is not None:
from pypy.tool.pytest.objspace import gettestobjspace
# Make cls.space and cls.runappdirect available in tests.
spaceconfig = getattr(appclass.obj, 'spaceconfig', {})
> appclass.obj.space = gettestobjspace(**spaceconfig)
conftest.py:259:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]}
config = <rpython.config.config.Config object at 0x0000016efc9cfe50>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000016efc9cfe50>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000016efc9cfe50>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000016efc9cfe50>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000016efcd43ca0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000016ef957bfa0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe498e40a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe498e4060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe498e3ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000016ef81d0608>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x0000016efe046410>, <W_TypeObject 'GenericAlias' at 0x16efa965b40>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x16efa706918>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x16efa706918>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x16efa706918>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x16efa706918>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x16ef8db03f0>>
w_obj = <W_TypeObject 'ellipsis' at 0x16efa706918>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x16efa706918>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x16ef8db03f0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x16efa706918>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x16ef8db03f0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x16ef8db03f0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x16ef8db03f0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'
..\rpython\rtyper\lltypesystem\lltype.py:1270: AttributeError
_________ ERROR at setup of AppTestExceptions.test_implicit_chaining __________
self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'>
func = <function <lambda> at 0x0000016ef9ac6020>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=item, **kwds), when=when)
..\_pytest\runner.py:138:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_HookCaller 'pytest_runtest_setup'>
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_implicit_chaining'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_implicit_chaining'>}
def __call__(self, **kwargs):
assert not self.is_historic()
> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
..\_pytest\vendored_packages\pluggy.py:724:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.config.PytestPluginManager object at 0x0000016ef37b1440>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000016efb453ba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000016ef3c766a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000016ef3c766e0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_implicit_chaining'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_implicit_chaining'>}
def _hookexec(self, hook, methods, kwargs):
# called from all hookcaller instances.
# enable_tracing will set its own wrapping function at self._inner_hookexec
> return self._inner_hookexec(hook, methods, kwargs)
..\_pytest\vendored_packages\pluggy.py:338:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000016efb453ba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000016ef3c766a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000016ef3c766e0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_implicit_chaining'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_implicit_chaining'>}
self._inner_hookexec = lambda hook, methods, kwargs: \
> _MultiCall(methods, kwargs, hook.spec_opts).execute()
..\_pytest\vendored_packages\pluggy.py:333:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_implicit_chaining'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
> return _wrapped_call(hook_impl.function(*args), self.execute)
..\_pytest\vendored_packages\pluggy.py:595:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
wrap_controller = <generator object pytest_runtest_setup at 0x0000016ef89b76c8>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...t_chaining'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>>
def _wrapped_call(wrap_controller, func):
""" Wrap calling to a function with a generator which needs to yield
exactly once. The yield point will trigger calling the wrapped function
and return its _CallOutcome to the yield point. The generator then needs
to finish (raise StopIteration) in order for the wrapped call to complete.
"""
try:
next(wrap_controller) # first yield
except StopIteration:
_raise_wrapfail(wrap_controller, "did not yield")
call_outcome = _CallOutcome(func)
try:
wrap_controller.send(call_outcome)
_raise_wrapfail(wrap_controller, "has second yield")
except StopIteration:
pass
> return call_outcome.get_result()
..\_pytest\vendored_packages\pluggy.py:253:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000016efd3a02a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000016efd3a02a0>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...t_chaining'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>>
def __init__(self, func):
try:
> self.result = func()
..\_pytest\vendored_packages\pluggy.py:264:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_implicit_chaining'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
return _wrapped_call(hook_impl.function(*args), self.execute)
> res = hook_impl.function(*args)
..\_pytest\vendored_packages\pluggy.py:596:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
item = <AppTestMethod 'test_implicit_chaining'>
@pytest.hookimpl(tryfirst=True)
def pytest_runtest_setup(item):
if isinstance(item, pytest.Function):
config = item.config
if get_marker(item, name='pypy_only'):
if config.applevel is not None and not config.applevel.is_pypy:
pytest.skip('PyPy-specific test')
appclass = item.getparent(pytest.Class)
if appclass is not None:
from pypy.tool.pytest.objspace import gettestobjspace
# Make cls.space and cls.runappdirect available in tests.
spaceconfig = getattr(appclass.obj, 'spaceconfig', {})
> appclass.obj.space = gettestobjspace(**spaceconfig)
conftest.py:259:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]}
config = <rpython.config.config.Config object at 0x0000016efd3969f8>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000016efd3969f8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000016efd3969f8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000016efd3969f8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000016efc5491e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000016efa3c6ad8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe498e40a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe498e4060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe498e3ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000016ef81d0608>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x0000016efd396f70>, <W_TypeObject 'GenericAlias' at 0x16efa791fa0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x16ef9c2e988>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x16ef9c2e988>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x16ef9c2e988>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x16ef9c2e988>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x16ef8db1950>>
w_obj = <W_TypeObject 'ellipsis' at 0x16ef9c2e988>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x16ef9c2e988>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x16ef8db1950>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x16ef9c2e988>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x16ef8db1950>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x16ef8db1950>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x16ef8db1950>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'
..\rpython\rtyper\lltypesystem\lltype.py:1270: AttributeError
ERROR at setup of AppTestExceptions.test_heaptype_dealloc_calls_base_tp_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 0x0000016efd10d268>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=item, **kwds), when=when)
..\_pytest\runner.py:138:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_HookCaller 'pytest_runtest_setup'>
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_heaptype_dealloc_calls_base_tp_...<_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_heaptype_dealloc_calls_base_tp_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 0x0000016ef37b1440>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000016efb453ba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000016ef3c766a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000016ef3c766e0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_heaptype_dealloc_calls_base_tp_...<_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_heaptype_dealloc_calls_base_tp_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 0x0000016efb453ba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000016ef3c766a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000016ef3c766e0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_heaptype_dealloc_calls_base_tp_...<_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_heaptype_dealloc_calls_base_tp_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_heaptype_dealloc_calls_base_tp_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 0x0000016efa93bc68>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...tp_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 0x0000016efc4ef620>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000016efc4ef620>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...tp_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_heaptype_dealloc_calls_base_tp_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_heaptype_dealloc_calls_base_tp_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 0x0000016efc852e20>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000016efc852e20>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000016efc852e20>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000016efc852e20>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000016efc87eaa0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000016ef9566720>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe498e40a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe498e4060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe498e3ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000016ef81d0608>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x0000016efc853398>, <W_TypeObject 'GenericAlias' at 0x16efa91fc58>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x16ef9e8bcc8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x16ef9e8bcc8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x16ef9e8bcc8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x16ef9e8bcc8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x16ef8db2b20>>
w_obj = <W_TypeObject 'ellipsis' at 0x16ef9e8bcc8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x16ef9e8bcc8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x16ef8db2b20>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x16ef9e8bcc8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x16ef8db2b20>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x16ef8db2b20>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x16ef8db2b20>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'
..\rpython\rtyper\lltypesystem\lltype.py:1270: AttributeError
========================== 8 error in 287.72 seconds ==========================
++ 06:35:04 starting module/cpyext/test/test_frameobject.py [66 started in total]
__ module/cpyext/test/test_eval.py [63 done in total, somefailed=True] ________
[platform:msg] Updated environment with vsver 160, using x64 True
[platform:msg] Updated environment with vsver 160, using x64 True
============================= test session starts =============================
platform win32 -- Python 2.7.18[pypy-7.3.18-alpha], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('d:\\pypy_stuff\\buildbot64\\slave\\own-win-x86-64\\build\\pypy\\.hypothesis\\examples')
pytest-2.9.2 from d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pytest.pyc
rootdir: d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 20 items
module\cpyext\test\test_eval.py EEEEEEEEEEEEEEEEEEEE
=================================== ERRORS ====================================
____________________ ERROR at setup of TestEval.test_eval _____________________
item = <Function 'test_eval'>
@pytest.hookimpl(tryfirst=True)
def pytest_runtest_setup(item):
if isinstance(item, pytest.Function):
config = item.config
if get_marker(item, name='pypy_only'):
if config.applevel is not None and not config.applevel.is_pypy:
pytest.skip('PyPy-specific test')
appclass = item.getparent(pytest.Class)
if appclass is not None:
from pypy.tool.pytest.objspace import gettestobjspace
# Make cls.space and cls.runappdirect available in tests.
spaceconfig = getattr(appclass.obj, 'spaceconfig', {})
> appclass.obj.space = gettestobjspace(**spaceconfig)
conftest.py: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 0x1b4e24cfb40>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'
..\rpython\rtyper\lltypesystem\lltype.py:1270: AttributeError
_________________ ERROR at setup of TestEval.test_call_object _________________
item = <Function 'test_call_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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
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 0x1b4e24ced00>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'
..\rpython\rtyper\lltypesystem\lltype.py:1270: AttributeError
__________________ ERROR at setup of TestEval.test_evalcode ___________________
item = <Function 'test_evalcode'>
@pytest.hookimpl(tryfirst=True)
def pytest_runtest_setup(item):
if isinstance(item, pytest.Function):
config = item.config
if get_marker(item, name='pypy_only'):
if config.applevel is not None and not config.applevel.is_pypy:
pytest.skip('PyPy-specific test')
appclass = item.getparent(pytest.Class)
if appclass is not None:
from pypy.tool.pytest.objspace 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 0x1b4e24cfed0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'
..\rpython\rtyper\lltypesystem\lltype.py:1270: AttributeError
_________________ ERROR at setup of TestEval.test_run_string __________________
item = <Function 'test_run_string'>
@pytest.hookimpl(tryfirst=True)
def pytest_runtest_setup(item):
if isinstance(item, pytest.Function):
config = item.config
if get_marker(item, name='pypy_only'):
if config.applevel is not None and not config.applevel.is_pypy:
pytest.skip('PyPy-specific test')
appclass = item.getparent(pytest.Class)
if appclass is not None:
from pypy.tool.pytest.objspace 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 0x1b4e24cf090>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'
..\rpython\rtyper\lltypesystem\lltype.py:1270: AttributeError
______________ ERROR at setup of TestEval.test_run_string_flags _______________
item = <Function 'test_run_string_flags'>
@pytest.hookimpl(tryfirst=True)
def pytest_runtest_setup(item):
if isinstance(item, pytest.Function):
config = item.config
if get_marker(item, name='pypy_only'):
if config.applevel is not None and not config.applevel.is_pypy:
pytest.skip('PyPy-specific test')
appclass = item.getparent(pytest.Class)
if appclass is not None:
from pypy.tool.pytest.objspace 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 0x1b4e24ce5e0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'
..\rpython\rtyper\lltypesystem\lltype.py:1270: AttributeError
__________________ ERROR at setup of TestEval.test_run_file ___________________
item = <Function 'test_run_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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
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 0x1b4e24cf7b0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'
..\rpython\rtyper\lltypesystem\lltype.py:1270: AttributeError
_________________ ERROR at setup of TestEval.test_getglobals __________________
item = <Function 'test_getglobals'>
@pytest.hookimpl(tryfirst=True)
def pytest_runtest_setup(item):
if isinstance(item, pytest.Function):
config = item.config
if get_marker(item, name='pypy_only'):
if config.applevel is not None and not config.applevel.is_pypy:
pytest.skip('PyPy-specific test')
appclass = item.getparent(pytest.Class)
if appclass is not None:
from pypy.tool.pytest.objspace 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 0x1b4e24cdec0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'
..\rpython\rtyper\lltypesystem\lltype.py:1270: AttributeError
_________________ ERROR at setup of TestEval.test_sliceindex __________________
item = <Function 'test_sliceindex'>
@pytest.hookimpl(tryfirst=True)
def pytest_runtest_setup(item):
if isinstance(item, pytest.Function):
config = item.config
if get_marker(item, name='pypy_only'):
if config.applevel is not None and not config.applevel.is_pypy:
pytest.skip('PyPy-specific test')
appclass = item.getparent(pytest.Class)
if appclass is not None:
from pypy.tool.pytest.objspace 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 0x1b4e24cc5d0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'
..\rpython\rtyper\lltypesystem\lltype.py:1270: AttributeError
___________________ ERROR at setup of TestEval.test_atexit ____________________
item = <Function 'test_atexit'>
@pytest.hookimpl(tryfirst=True)
def pytest_runtest_setup(item):
if isinstance(item, pytest.Function):
config = item.config
if get_marker(item, name='pypy_only'):
if config.applevel is not None and not config.applevel.is_pypy:
pytest.skip('PyPy-specific test')
appclass = item.getparent(pytest.Class)
if appclass is not None:
from pypy.tool.pytest.objspace 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 0x1b4e24cc960>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'
..\rpython\rtyper\lltypesystem\lltype.py:1270: AttributeError
____________ ERROR at setup of AppTestCall.test_run_simple_string _____________
self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'>
func = <function <lambda> at 0x000001b4e859e4d0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=item, **kwds), when=when)
..\_pytest\runner.py:138:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_HookCaller 'pytest_runtest_setup'>
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_run_simple_string'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_run_simple_string'>}
def __call__(self, **kwargs):
assert not self.is_historic()
> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
..\_pytest\vendored_packages\pluggy.py:724:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.config.PytestPluginManager object at 0x000001b4e01e3408>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001b4e800a460>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001b4e06a6660>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001b4e06a66a0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_run_simple_string'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_run_simple_string'>}
def _hookexec(self, hook, methods, kwargs):
# called from all hookcaller instances.
# enable_tracing will set its own wrapping function at self._inner_hookexec
> return self._inner_hookexec(hook, methods, kwargs)
..\_pytest\vendored_packages\pluggy.py:338:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001b4e800a460>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001b4e06a6660>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001b4e06a66a0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_run_simple_string'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_run_simple_string'>}
self._inner_hookexec = lambda hook, methods, kwargs: \
> _MultiCall(methods, kwargs, hook.spec_opts).execute()
..\_pytest\vendored_packages\pluggy.py:333:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_run_simple_string'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
> return _wrapped_call(hook_impl.function(*args), self.execute)
..\_pytest\vendored_packages\pluggy.py:595:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
wrap_controller = <generator object pytest_runtest_setup at 0x000001b4e72ffa38>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ple_string'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>>
def _wrapped_call(wrap_controller, func):
""" Wrap calling to a function with a generator which needs to yield
exactly once. The yield point will trigger calling the wrapped function
and return its _CallOutcome to the yield point. The generator then needs
to finish (raise StopIteration) in order for the wrapped call to complete.
"""
try:
next(wrap_controller) # first yield
except StopIteration:
_raise_wrapfail(wrap_controller, "did not yield")
call_outcome = _CallOutcome(func)
try:
wrap_controller.send(call_outcome)
_raise_wrapfail(wrap_controller, "has second yield")
except StopIteration:
pass
> return call_outcome.get_result()
..\_pytest\vendored_packages\pluggy.py:253:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001b4e96e5560>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001b4e96e5560>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ple_string'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>>
def __init__(self, func):
try:
> self.result = func()
..\_pytest\vendored_packages\pluggy.py:264:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_run_simple_string'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
return _wrapped_call(hook_impl.function(*args), self.execute)
> res = hook_impl.function(*args)
..\_pytest\vendored_packages\pluggy.py:596:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
item = <AppTestMethod 'test_run_simple_string'>
@pytest.hookimpl(tryfirst=True)
def pytest_runtest_setup(item):
if isinstance(item, pytest.Function):
config = item.config
if get_marker(item, name='pypy_only'):
if config.applevel is not None and not config.applevel.is_pypy:
pytest.skip('PyPy-specific test')
appclass = item.getparent(pytest.Class)
if appclass is not None:
from pypy.tool.pytest.objspace import gettestobjspace
# Make cls.space and cls.runappdirect available in tests.
spaceconfig = getattr(appclass.obj, 'spaceconfig', {})
> appclass.obj.space = gettestobjspace(**spaceconfig)
conftest.py:259:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]}
config = <rpython.config.config.Config object at 0x000001b4ea2ad3d0>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001b4ea2ad3d0>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001b4ea2ad3d0>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000001b4ea2ad3d0>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000001b4e97f4a60>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000001b4e9a161e0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe499940a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49994060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49993ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000001b4e4c05328>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x000001b4ea2ad948>, <W_TypeObject 'GenericAlias' at 0x1b4e70aa790>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b4e66ec7c8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b4e66ec7c8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b4e66ec7c8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b4e66ec7c8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b4e24cccf0>>
w_obj = <W_TypeObject 'ellipsis' at 0x1b4e66ec7c8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x1b4e66ec7c8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b4e24cccf0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x1b4e66ec7c8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b4e24cccf0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b4e24cccf0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b4e24cccf0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'
..\rpython\rtyper\lltypesystem\lltype.py:1270: AttributeError
_______________ ERROR at setup of AppTestCall.test_eval_code_ex _______________
self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'>
func = <function <lambda> at 0x000001b4eb4b6908>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=item, **kwds), when=when)
..\_pytest\runner.py:138:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_HookCaller 'pytest_runtest_setup'>
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_eval_code_ex'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_eval_code_ex'>}
def __call__(self, **kwargs):
assert not self.is_historic()
> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
..\_pytest\vendored_packages\pluggy.py:724:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.config.PytestPluginManager object at 0x000001b4e01e3408>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001b4e800a460>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001b4e06a6660>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001b4e06a66a0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_eval_code_ex'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_eval_code_ex'>}
def _hookexec(self, hook, methods, kwargs):
# called from all hookcaller instances.
# enable_tracing will set its own wrapping function at self._inner_hookexec
> return self._inner_hookexec(hook, methods, kwargs)
..\_pytest\vendored_packages\pluggy.py:338:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001b4e800a460>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001b4e06a6660>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001b4e06a66a0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_eval_code_ex'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_eval_code_ex'>}
self._inner_hookexec = lambda hook, methods, kwargs: \
> _MultiCall(methods, kwargs, hook.spec_opts).execute()
..\_pytest\vendored_packages\pluggy.py:333:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_eval_code_ex'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
> return _wrapped_call(hook_impl.function(*args), self.execute)
..\_pytest\vendored_packages\pluggy.py:595:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
wrap_controller = <generator object pytest_runtest_setup at 0x000001b4e60f9d80>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...al_code_ex'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>>
def _wrapped_call(wrap_controller, func):
""" Wrap calling to a function with a generator which needs to yield
exactly once. The yield point will trigger calling the wrapped function
and return its _CallOutcome to the yield point. The generator then needs
to finish (raise StopIteration) in order for the wrapped call to complete.
"""
try:
next(wrap_controller) # first yield
except StopIteration:
_raise_wrapfail(wrap_controller, "did not yield")
call_outcome = _CallOutcome(func)
try:
wrap_controller.send(call_outcome)
_raise_wrapfail(wrap_controller, "has second yield")
except StopIteration:
pass
> return call_outcome.get_result()
..\_pytest\vendored_packages\pluggy.py:253:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001b4e96b5220>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001b4e96b5220>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...al_code_ex'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>>
def __init__(self, func):
try:
> self.result = func()
..\_pytest\vendored_packages\pluggy.py:264:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_eval_code_ex'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
return _wrapped_call(hook_impl.function(*args), self.execute)
> res = hook_impl.function(*args)
..\_pytest\vendored_packages\pluggy.py:596:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
item = <AppTestMethod 'test_eval_code_ex'>
@pytest.hookimpl(tryfirst=True)
def pytest_runtest_setup(item):
if isinstance(item, pytest.Function):
config = item.config
if get_marker(item, name='pypy_only'):
if config.applevel is not None and not config.applevel.is_pypy:
pytest.skip('PyPy-specific test')
appclass = item.getparent(pytest.Class)
if appclass is not None:
from pypy.tool.pytest.objspace import gettestobjspace
# Make cls.space and cls.runappdirect available in tests.
spaceconfig = getattr(appclass.obj, 'spaceconfig', {})
> appclass.obj.space = gettestobjspace(**spaceconfig)
conftest.py:259:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]}
config = <rpython.config.config.Config object at 0x000001b4e9fb5a60>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001b4e9fb5a60>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001b4e9fb5a60>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000001b4e9fb5a60>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000001b4eac24620>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000001b4e67adad0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe498e40a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe498e4060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe498e3ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000001b4e4c05328>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x000001b4eac5a020>, <W_TypeObject 'GenericAlias' at 0x1b4e6e4f050>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b4e679def8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b4e679def8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b4e679def8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b4e679def8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b4e07a3490>>
w_obj = <W_TypeObject 'ellipsis' at 0x1b4e679def8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x1b4e679def8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b4e07a3490>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x1b4e679def8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b4e07a3490>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b4e07a3490>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b4e07a3490>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'
..\rpython\rtyper\lltypesystem\lltype.py:1270: AttributeError
_______________ ERROR at setup of AppTestCall.test_CallFunction _______________
self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'>
func = <function <lambda> at 0x000001b4e67789f8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=item, **kwds), when=when)
..\_pytest\runner.py:138:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_HookCaller 'pytest_runtest_setup'>
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_CallFunction'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_CallFunction'>}
def __call__(self, **kwargs):
assert not self.is_historic()
> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
..\_pytest\vendored_packages\pluggy.py:724:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.config.PytestPluginManager object at 0x000001b4e01e3408>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001b4e800a460>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001b4e06a6660>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001b4e06a66a0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_CallFunction'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_CallFunction'>}
def _hookexec(self, hook, methods, kwargs):
# called from all hookcaller instances.
# enable_tracing will set its own wrapping function at self._inner_hookexec
> return self._inner_hookexec(hook, methods, kwargs)
..\_pytest\vendored_packages\pluggy.py:338:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001b4e800a460>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001b4e06a6660>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001b4e06a66a0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_CallFunction'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_CallFunction'>}
self._inner_hookexec = lambda hook, methods, kwargs: \
> _MultiCall(methods, kwargs, hook.spec_opts).execute()
..\_pytest\vendored_packages\pluggy.py:333:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_CallFunction'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
> return _wrapped_call(hook_impl.function(*args), self.execute)
..\_pytest\vendored_packages\pluggy.py:595:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
wrap_controller = <generator object pytest_runtest_setup at 0x000001b4e7063c18>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...llFunction'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>>
def _wrapped_call(wrap_controller, func):
""" Wrap calling to a function with a generator which needs to yield
exactly once. The yield point will trigger calling the wrapped function
and return its _CallOutcome to the yield point. The generator then needs
to finish (raise StopIteration) in order for the wrapped call to complete.
"""
try:
next(wrap_controller) # first yield
except StopIteration:
_raise_wrapfail(wrap_controller, "did not yield")
call_outcome = _CallOutcome(func)
try:
wrap_controller.send(call_outcome)
_raise_wrapfail(wrap_controller, "has second yield")
except StopIteration:
pass
> return call_outcome.get_result()
..\_pytest\vendored_packages\pluggy.py:253:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001b4ead0c6e0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001b4ead0c6e0>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...llFunction'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>>
def __init__(self, func):
try:
> self.result = func()
..\_pytest\vendored_packages\pluggy.py:264:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_CallFunction'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
return _wrapped_call(hook_impl.function(*args), self.execute)
> res = hook_impl.function(*args)
..\_pytest\vendored_packages\pluggy.py:596:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
item = <AppTestMethod 'test_CallFunction'>
@pytest.hookimpl(tryfirst=True)
def pytest_runtest_setup(item):
if isinstance(item, pytest.Function):
config = item.config
if get_marker(item, name='pypy_only'):
if config.applevel is not None and not config.applevel.is_pypy:
pytest.skip('PyPy-specific test')
appclass = item.getparent(pytest.Class)
if appclass is not None:
from pypy.tool.pytest.objspace import gettestobjspace
# Make cls.space and cls.runappdirect available in tests.
spaceconfig = getattr(appclass.obj, 'spaceconfig', {})
> appclass.obj.space = gettestobjspace(**spaceconfig)
conftest.py:259:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]}
config = <rpython.config.config.Config object at 0x000001b4eacbb168>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001b4eacbb168>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001b4eacbb168>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000001b4eacbb168>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000001b4ead0d720>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000001b4e9290ad8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe499940a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49994060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49993ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000001b4e4c05328>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x000001b4eacbb6e0>, <W_TypeObject 'GenericAlias' at 0x1b4e70c0170>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b4e66ec988>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b4e66ec988>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b4e66ec988>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b4e66ec988>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b4e07a29e0>>
w_obj = <W_TypeObject 'ellipsis' at 0x1b4e66ec988>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x1b4e66ec988>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b4e07a29e0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x1b4e66ec988>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b4e07a29e0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b4e07a29e0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b4e07a29e0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'
..\rpython\rtyper\lltypesystem\lltype.py:1270: AttributeError
______ ERROR at setup of AppTestCall.test_CallFunction_PY_SSIZE_T_CLEAN _______
self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'>
func = <function <lambda> at 0x000001b4eb196188>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=item, **kwds), when=when)
..\_pytest\runner.py:138:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_HookCaller 'pytest_runtest_setup'>
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_CallFunction_PY_SSIZE_T_CLEAN'>...call__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_CallFunction_PY_SSIZE_T_CLEAN'>}
def __call__(self, **kwargs):
assert not self.is_historic()
> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
..\_pytest\vendored_packages\pluggy.py:724:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.config.PytestPluginManager object at 0x000001b4e01e3408>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001b4e800a460>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001b4e06a6660>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001b4e06a66a0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_CallFunction_PY_SSIZE_T_CLEAN'>...call__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_CallFunction_PY_SSIZE_T_CLEAN'>}
def _hookexec(self, hook, methods, kwargs):
# called from all hookcaller instances.
# enable_tracing will set its own wrapping function at self._inner_hookexec
> return self._inner_hookexec(hook, methods, kwargs)
..\_pytest\vendored_packages\pluggy.py:338:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001b4e800a460>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001b4e06a6660>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001b4e06a66a0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_CallFunction_PY_SSIZE_T_CLEAN'>...call__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_CallFunction_PY_SSIZE_T_CLEAN'>}
self._inner_hookexec = lambda hook, methods, kwargs: \
> _MultiCall(methods, kwargs, hook.spec_opts).execute()
..\_pytest\vendored_packages\pluggy.py:333:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_CallFunction_PY_SSIZE_T_CLEAN'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
> return _wrapped_call(hook_impl.function(*args), self.execute)
..\_pytest\vendored_packages\pluggy.py:595:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
wrap_controller = <generator object pytest_runtest_setup at 0x000001b4e79795d8>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ZE_T_CLEAN'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>>
def _wrapped_call(wrap_controller, func):
""" Wrap calling to a function with a generator which needs to yield
exactly once. The yield point will trigger calling the wrapped function
and return its _CallOutcome to the yield point. The generator then needs
to finish (raise StopIteration) in order for the wrapped call to complete.
"""
try:
next(wrap_controller) # first yield
except StopIteration:
_raise_wrapfail(wrap_controller, "did not yield")
call_outcome = _CallOutcome(func)
try:
wrap_controller.send(call_outcome)
_raise_wrapfail(wrap_controller, "has second yield")
except StopIteration:
pass
> return call_outcome.get_result()
..\_pytest\vendored_packages\pluggy.py:253:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001b4e9a0eee0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001b4e9a0eee0>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ZE_T_CLEAN'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>>
def __init__(self, func):
try:
> self.result = func()
..\_pytest\vendored_packages\pluggy.py:264:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_CallFunction_PY_SSIZE_T_CLEAN'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
return _wrapped_call(hook_impl.function(*args), self.execute)
> res = hook_impl.function(*args)
..\_pytest\vendored_packages\pluggy.py:596:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
item = <AppTestMethod 'test_CallFunction_PY_SSIZE_T_CLEAN'>
@pytest.hookimpl(tryfirst=True)
def pytest_runtest_setup(item):
if isinstance(item, pytest.Function):
config = item.config
if get_marker(item, name='pypy_only'):
if config.applevel is not None and not config.applevel.is_pypy:
pytest.skip('PyPy-specific test')
appclass = item.getparent(pytest.Class)
if appclass is not None:
from pypy.tool.pytest.objspace import gettestobjspace
# Make cls.space and cls.runappdirect available in tests.
spaceconfig = getattr(appclass.obj, 'spaceconfig', {})
> appclass.obj.space = gettestobjspace(**spaceconfig)
conftest.py:259:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]}
config = <rpython.config.config.Config object at 0x000001b4ea1bf7c0>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001b4ea1bf7c0>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001b4ea1bf7c0>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000001b4ea1bf7c0>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000001b4e9a0ff60>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000001b4e69ac720>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe499940a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49994060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49993ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000001b4e4c05328>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x000001b4ea1bfd38>, <W_TypeObject 'GenericAlias' at 0x1b4e72758a0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b4e676cbb8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b4e676cbb8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b4e676cbb8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b4e676cbb8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b4e24cdb30>>
w_obj = <W_TypeObject 'ellipsis' at 0x1b4e676cbb8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x1b4e676cbb8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b4e24cdb30>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x1b4e676cbb8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b4e24cdb30>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b4e24cdb30>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b4e24cdb30>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'
..\rpython\rtyper\lltypesystem\lltype.py:1270: AttributeError
___________ ERROR at setup of AppTestCall.test_CallFunctionObjArgs ____________
self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'>
func = <function <lambda> at 0x000001b4e9d27970>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=item, **kwds), when=when)
..\_pytest\runner.py:138:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_HookCaller 'pytest_runtest_setup'>
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_CallFunctionObjArgs'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_CallFunctionObjArgs'>}
def __call__(self, **kwargs):
assert not self.is_historic()
> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
..\_pytest\vendored_packages\pluggy.py:724:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.config.PytestPluginManager object at 0x000001b4e01e3408>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001b4e800a460>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001b4e06a6660>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001b4e06a66a0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_CallFunctionObjArgs'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_CallFunctionObjArgs'>}
def _hookexec(self, hook, methods, kwargs):
# called from all hookcaller instances.
# enable_tracing will set its own wrapping function at self._inner_hookexec
> return self._inner_hookexec(hook, methods, kwargs)
..\_pytest\vendored_packages\pluggy.py:338:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001b4e800a460>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001b4e06a6660>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001b4e06a66a0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_CallFunctionObjArgs'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_CallFunctionObjArgs'>}
self._inner_hookexec = lambda hook, methods, kwargs: \
> _MultiCall(methods, kwargs, hook.spec_opts).execute()
..\_pytest\vendored_packages\pluggy.py:333:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_CallFunctionObjArgs'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
> return _wrapped_call(hook_impl.function(*args), self.execute)
..\_pytest\vendored_packages\pluggy.py:595:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
wrap_controller = <generator object pytest_runtest_setup at 0x000001b4e7c2fab0>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ionObjArgs'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>>
def _wrapped_call(wrap_controller, func):
""" Wrap calling to a function with a generator which needs to yield
exactly once. The yield point will trigger calling the wrapped function
and return its _CallOutcome to the yield point. The generator then needs
to finish (raise StopIteration) in order for the wrapped call to complete.
"""
try:
next(wrap_controller) # first yield
except StopIteration:
_raise_wrapfail(wrap_controller, "did not yield")
call_outcome = _CallOutcome(func)
try:
wrap_controller.send(call_outcome)
_raise_wrapfail(wrap_controller, "has second yield")
except StopIteration:
pass
> return call_outcome.get_result()
..\_pytest\vendored_packages\pluggy.py:253:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001b4eac3f660>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001b4eac3f660>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ionObjArgs'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>>
def __init__(self, func):
try:
> self.result = func()
..\_pytest\vendored_packages\pluggy.py:264:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_CallFunctionObjArgs'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
return _wrapped_call(hook_impl.function(*args), self.execute)
> res = hook_impl.function(*args)
..\_pytest\vendored_packages\pluggy.py:596:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
item = <AppTestMethod 'test_CallFunctionObjArgs'>
@pytest.hookimpl(tryfirst=True)
def pytest_runtest_setup(item):
if isinstance(item, pytest.Function):
config = item.config
if get_marker(item, name='pypy_only'):
if config.applevel is not None and not config.applevel.is_pypy:
pytest.skip('PyPy-specific test')
appclass = item.getparent(pytest.Class)
if appclass is not None:
from pypy.tool.pytest.objspace import gettestobjspace
# Make cls.space and cls.runappdirect available in tests.
spaceconfig = getattr(appclass.obj, 'spaceconfig', {})
> appclass.obj.space = gettestobjspace(**spaceconfig)
conftest.py:259:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]}
config = <rpython.config.config.Config object at 0x000001b4eaeecfe0>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001b4eaeecfe0>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001b4eaeecfe0>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000001b4eaeecfe0>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000001b4ea05a8a0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000001b4e68c7a60>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe499940a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49994060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49993ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000001b4e4c05328>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x000001b4eaeed558>, <W_TypeObject 'GenericAlias' at 0x1b4e6fc2d08>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b4e70279f0>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b4e70279f0>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b4e70279f0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b4e70279f0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b4e07a1f30>>
w_obj = <W_TypeObject 'ellipsis' at 0x1b4e70279f0>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x1b4e70279f0>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b4e07a1f30>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x1b4e70279f0>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b4e07a1f30>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b4e07a1f30>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b4e07a1f30>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'
..\rpython\rtyper\lltypesystem\lltype.py:1270: AttributeError
__________ ERROR at setup of AppTestCall.test_CompileString_and_Exec __________
self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'>
func = <function <lambda> at 0x000001b4e914f718>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=item, **kwds), when=when)
..\_pytest\runner.py:138:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_HookCaller 'pytest_runtest_setup'>
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_CompileString_and_Exec'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_CompileString_and_Exec'>}
def __call__(self, **kwargs):
assert not self.is_historic()
> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
..\_pytest\vendored_packages\pluggy.py:724:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.config.PytestPluginManager object at 0x000001b4e01e3408>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001b4e800a460>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001b4e06a6660>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001b4e06a66a0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_CompileString_and_Exec'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_CompileString_and_Exec'>}
def _hookexec(self, hook, methods, kwargs):
# called from all hookcaller instances.
# enable_tracing will set its own wrapping function at self._inner_hookexec
> return self._inner_hookexec(hook, methods, kwargs)
..\_pytest\vendored_packages\pluggy.py:338:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001b4e800a460>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001b4e06a6660>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001b4e06a66a0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_CompileString_and_Exec'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_CompileString_and_Exec'>}
self._inner_hookexec = lambda hook, methods, kwargs: \
> _MultiCall(methods, kwargs, hook.spec_opts).execute()
..\_pytest\vendored_packages\pluggy.py:333:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_CompileString_and_Exec'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
> return _wrapped_call(hook_impl.function(*args), self.execute)
..\_pytest\vendored_packages\pluggy.py:595:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
wrap_controller = <generator object pytest_runtest_setup at 0x000001b4e60fe840>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...g_and_Exec'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>>
def _wrapped_call(wrap_controller, func):
""" Wrap calling to a function with a generator which needs to yield
exactly once. The yield point will trigger calling the wrapped function
and return its _CallOutcome to the yield point. The generator then needs
to finish (raise StopIteration) in order for the wrapped call to complete.
"""
try:
next(wrap_controller) # first yield
except StopIteration:
_raise_wrapfail(wrap_controller, "did not yield")
call_outcome = _CallOutcome(func)
try:
wrap_controller.send(call_outcome)
_raise_wrapfail(wrap_controller, "has second yield")
except StopIteration:
pass
> return call_outcome.get_result()
..\_pytest\vendored_packages\pluggy.py:253:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001b4e92b2620>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001b4e92b2620>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...g_and_Exec'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>>
def __init__(self, func):
try:
> self.result = func()
..\_pytest\vendored_packages\pluggy.py:264:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_CompileString_and_Exec'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
return _wrapped_call(hook_impl.function(*args), self.execute)
> res = hook_impl.function(*args)
..\_pytest\vendored_packages\pluggy.py:596:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
item = <AppTestMethod 'test_CompileString_and_Exec'>
@pytest.hookimpl(tryfirst=True)
def pytest_runtest_setup(item):
if isinstance(item, pytest.Function):
config = item.config
if get_marker(item, name='pypy_only'):
if config.applevel is not None and not config.applevel.is_pypy:
pytest.skip('PyPy-specific test')
appclass = item.getparent(pytest.Class)
if appclass is not None:
from pypy.tool.pytest.objspace import gettestobjspace
# Make cls.space and cls.runappdirect available in tests.
spaceconfig = getattr(appclass.obj, 'spaceconfig', {})
> appclass.obj.space = gettestobjspace(**spaceconfig)
conftest.py:259:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]}
config = <rpython.config.config.Config object at 0x000001b4e9fc1600>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001b4e9fc1600>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001b4e9fc1600>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000001b4e9fc1600>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000001b4e92b37a0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000001b4e97290c0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe498e40a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe498e4060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe498e3ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000001b4e4c05328>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x000001b4e9fc1b78>, <W_TypeObject 'GenericAlias' at 0x1b4e711b328>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b4e7446f38>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b4e7446f38>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b4e7446f38>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b4e7446f38>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b4e5c9cb00>>
w_obj = <W_TypeObject 'ellipsis' at 0x1b4e7446f38>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x1b4e7446f38>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b4e5c9cb00>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x1b4e7446f38>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b4e5c9cb00>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b4e5c9cb00>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b4e5c9cb00>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'
..\rpython\rtyper\lltypesystem\lltype.py:1270: AttributeError
___________ ERROR at setup of AppTestCall.test_merge_compiler_flags ___________
self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'>
func = <function <lambda> at 0x000001b4e54371f0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=item, **kwds), when=when)
..\_pytest\runner.py:138:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_HookCaller 'pytest_runtest_setup'>
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_merge_compiler_flags'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_merge_compiler_flags'>}
def __call__(self, **kwargs):
assert not self.is_historic()
> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
..\_pytest\vendored_packages\pluggy.py:724:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.config.PytestPluginManager object at 0x000001b4e01e3408>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001b4e800a460>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001b4e06a6660>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001b4e06a66a0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_merge_compiler_flags'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_merge_compiler_flags'>}
def _hookexec(self, hook, methods, kwargs):
# called from all hookcaller instances.
# enable_tracing will set its own wrapping function at self._inner_hookexec
> return self._inner_hookexec(hook, methods, kwargs)
..\_pytest\vendored_packages\pluggy.py:338:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001b4e800a460>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001b4e06a6660>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001b4e06a66a0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_merge_compiler_flags'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_merge_compiler_flags'>}
self._inner_hookexec = lambda hook, methods, kwargs: \
> _MultiCall(methods, kwargs, hook.spec_opts).execute()
..\_pytest\vendored_packages\pluggy.py:333:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_merge_compiler_flags'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
> return _wrapped_call(hook_impl.function(*args), self.execute)
..\_pytest\vendored_packages\pluggy.py:595:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
wrap_controller = <generator object pytest_runtest_setup at 0x000001b4e701a930>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...iler_flags'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>>
def _wrapped_call(wrap_controller, func):
""" Wrap calling to a function with a generator which needs to yield
exactly once. The yield point will trigger calling the wrapped function
and return its _CallOutcome to the yield point. The generator then needs
to finish (raise StopIteration) in order for the wrapped call to complete.
"""
try:
next(wrap_controller) # first yield
except StopIteration:
_raise_wrapfail(wrap_controller, "did not yield")
call_outcome = _CallOutcome(func)
try:
wrap_controller.send(call_outcome)
_raise_wrapfail(wrap_controller, "has second yield")
except StopIteration:
pass
> return call_outcome.get_result()
..\_pytest\vendored_packages\pluggy.py:253:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001b4eab004a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001b4eab004a0>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...iler_flags'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>>
def __init__(self, func):
try:
> self.result = func()
..\_pytest\vendored_packages\pluggy.py:264:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_merge_compiler_flags'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
return _wrapped_call(hook_impl.function(*args), self.execute)
> res = hook_impl.function(*args)
..\_pytest\vendored_packages\pluggy.py:596:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
item = <AppTestMethod 'test_merge_compiler_flags'>
@pytest.hookimpl(tryfirst=True)
def pytest_runtest_setup(item):
if isinstance(item, pytest.Function):
config = item.config
if get_marker(item, name='pypy_only'):
if config.applevel is not None and not config.applevel.is_pypy:
pytest.skip('PyPy-specific test')
appclass = item.getparent(pytest.Class)
if appclass is not None:
from pypy.tool.pytest.objspace import gettestobjspace
# Make cls.space and cls.runappdirect available in tests.
spaceconfig = getattr(appclass.obj, 'spaceconfig', {})
> appclass.obj.space = gettestobjspace(**spaceconfig)
conftest.py:259:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]}
config = <rpython.config.config.Config object at 0x000001b4e9f96368>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001b4e9f96368>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001b4e9f96368>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000001b4e9f96368>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000001b4e9f7f460>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000001b4e9313088>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe499940a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49994060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49993ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000001b4e4c05328>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x000001b4e9f968e0>, <W_TypeObject 'GenericAlias' at 0x1b4e73158a0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b4e74466e8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b4e74466e8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b4e74466e8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b4e74466e8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b4e5c9d5b0>>
w_obj = <W_TypeObject 'ellipsis' at 0x1b4e74466e8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x1b4e74466e8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b4e5c9d5b0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x1b4e74466e8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b4e5c9d5b0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b4e5c9d5b0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b4e5c9d5b0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'
..\rpython\rtyper\lltypesystem\lltype.py:1270: AttributeError
____________ ERROR at setup of AppTestCall.test_recursive_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 0x000001b4e6f947a0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=item, **kwds), when=when)
..\_pytest\runner.py:138:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_HookCaller 'pytest_runtest_setup'>
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_recursive_function'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_recursive_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 0x000001b4e01e3408>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001b4e800a460>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001b4e06a6660>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001b4e06a66a0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_recursive_function'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_recursive_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 0x000001b4e800a460>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001b4e06a6660>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001b4e06a66a0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_recursive_function'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_recursive_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_recursive_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 0x000001b4e79df448>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...e_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 0x000001b4e93d8f60>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001b4e93d8f60>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...e_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_recursive_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_recursive_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 = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]}
config = <rpython.config.config.Config object at 0x000001b4e96c14e8>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001b4e96c14e8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001b4e96c14e8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000001b4e96c14e8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000001b4e93d9f60>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000001b4e9385130>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe499540a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49954060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49953ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000001b4e4c05328>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x000001b4e96c1a60>, <W_TypeObject 'GenericAlias' at 0x1b4e72249c0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b4e69d2e58>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b4e69d2e58>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b4e69d2e58>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b4e69d2e58>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b4e5c9c050>>
w_obj = <W_TypeObject 'ellipsis' at 0x1b4e69d2e58>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x1b4e69d2e58>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b4e5c9c050>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x1b4e69d2e58>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b4e5c9c050>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b4e5c9c050>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b4e5c9c050>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'
..\rpython\rtyper\lltypesystem\lltype.py:1270: AttributeError
_______________ ERROR at setup of AppTestCall.test_build_class ________________
self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'>
func = <function <lambda> at 0x000001b4e72b9970>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=item, **kwds), when=when)
..\_pytest\runner.py:138:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_HookCaller 'pytest_runtest_setup'>
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_build_class'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_build_class'>}
def __call__(self, **kwargs):
assert not self.is_historic()
> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
..\_pytest\vendored_packages\pluggy.py:724:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.config.PytestPluginManager object at 0x000001b4e01e3408>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001b4e800a460>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001b4e06a6660>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001b4e06a66a0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_build_class'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_build_class'>}
def _hookexec(self, hook, methods, kwargs):
# called from all hookcaller instances.
# enable_tracing will set its own wrapping function at self._inner_hookexec
> return self._inner_hookexec(hook, methods, kwargs)
..\_pytest\vendored_packages\pluggy.py:338:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001b4e800a460>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001b4e06a6660>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001b4e06a66a0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_build_class'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_build_class'>}
self._inner_hookexec = lambda hook, methods, kwargs: \
> _MultiCall(methods, kwargs, hook.spec_opts).execute()
..\_pytest\vendored_packages\pluggy.py:333:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_build_class'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
> return _wrapped_call(hook_impl.function(*args), self.execute)
..\_pytest\vendored_packages\pluggy.py:595:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
wrap_controller = <generator object pytest_runtest_setup at 0x000001b4e7c2e368>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...uild_class'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>>
def _wrapped_call(wrap_controller, func):
""" Wrap calling to a function with a generator which needs to yield
exactly once. The yield point will trigger calling the wrapped function
and return its _CallOutcome to the yield point. The generator then needs
to finish (raise StopIteration) in order for the wrapped call to complete.
"""
try:
next(wrap_controller) # first yield
except StopIteration:
_raise_wrapfail(wrap_controller, "did not yield")
call_outcome = _CallOutcome(func)
try:
wrap_controller.send(call_outcome)
_raise_wrapfail(wrap_controller, "has second yield")
except StopIteration:
pass
> return call_outcome.get_result()
..\_pytest\vendored_packages\pluggy.py:253:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001b4e99e7f60>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001b4e99e7f60>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...uild_class'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>>
def __init__(self, func):
try:
> self.result = func()
..\_pytest\vendored_packages\pluggy.py:264:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_build_class'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
return _wrapped_call(hook_impl.function(*args), self.execute)
> res = hook_impl.function(*args)
..\_pytest\vendored_packages\pluggy.py:596:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
item = <AppTestMethod 'test_build_class'>
@pytest.hookimpl(tryfirst=True)
def pytest_runtest_setup(item):
if isinstance(item, pytest.Function):
config = item.config
if get_marker(item, name='pypy_only'):
if config.applevel is not None and not config.applevel.is_pypy:
pytest.skip('PyPy-specific test')
appclass = item.getparent(pytest.Class)
if appclass is not None:
from pypy.tool.pytest.objspace import gettestobjspace
# Make cls.space and cls.runappdirect available in tests.
spaceconfig = getattr(appclass.obj, 'spaceconfig', {})
> appclass.obj.space = gettestobjspace(**spaceconfig)
conftest.py:259:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]}
config = <rpython.config.config.Config object at 0x000001b4e9e2b440>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001b4e9e2b440>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001b4e9e2b440>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000001b4e9e2b440>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000001b4ea1e5020>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000001b4e946f5c8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe499540a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49954060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49953ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000001b4e4c05328>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x000001b4e9e2b9b8>, <W_TypeObject 'GenericAlias' at 0x1b4e711acd0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b4e72742f8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b4e72742f8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b4e72742f8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b4e72742f8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b4e5c9b5a0>>
w_obj = <W_TypeObject 'ellipsis' at 0x1b4e72742f8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x1b4e72742f8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b4e5c9b5a0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x1b4e72742f8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b4e5c9b5a0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b4e5c9b5a0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b4e5c9b5a0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'
..\rpython\rtyper\lltypesystem\lltype.py:1270: AttributeError
_________________ ERROR at setup of AppTestCall.test_getframe _________________
self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'>
func = <function <lambda> at 0x000001b4e85533d0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=item, **kwds), when=when)
..\_pytest\runner.py:138:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_HookCaller 'pytest_runtest_setup'>
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_getframe'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_getframe'>}
def __call__(self, **kwargs):
assert not self.is_historic()
> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
..\_pytest\vendored_packages\pluggy.py:724:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.config.PytestPluginManager object at 0x000001b4e01e3408>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001b4e800a460>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001b4e06a6660>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001b4e06a66a0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_getframe'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_getframe'>}
def _hookexec(self, hook, methods, kwargs):
# called from all hookcaller instances.
# enable_tracing will set its own wrapping function at self._inner_hookexec
> return self._inner_hookexec(hook, methods, kwargs)
..\_pytest\vendored_packages\pluggy.py:338:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001b4e800a460>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001b4e06a6660>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001b4e06a66a0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_getframe'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_getframe'>}
self._inner_hookexec = lambda hook, methods, kwargs: \
> _MultiCall(methods, kwargs, hook.spec_opts).execute()
..\_pytest\vendored_packages\pluggy.py:333:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_getframe'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
> return _wrapped_call(hook_impl.function(*args), self.execute)
..\_pytest\vendored_packages\pluggy.py:595:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
wrap_controller = <generator object pytest_runtest_setup at 0x000001b4e62f9100>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...t_getframe'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>>
def _wrapped_call(wrap_controller, func):
""" Wrap calling to a function with a generator which needs to yield
exactly once. The yield point will trigger calling the wrapped function
and return its _CallOutcome to the yield point. The generator then needs
to finish (raise StopIteration) in order for the wrapped call to complete.
"""
try:
next(wrap_controller) # first yield
except StopIteration:
_raise_wrapfail(wrap_controller, "did not yield")
call_outcome = _CallOutcome(func)
try:
wrap_controller.send(call_outcome)
_raise_wrapfail(wrap_controller, "has second yield")
except StopIteration:
pass
> return call_outcome.get_result()
..\_pytest\vendored_packages\pluggy.py:253:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001b4e9e446a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001b4e9e446a0>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...t_getframe'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>>
def __init__(self, func):
try:
> self.result = func()
..\_pytest\vendored_packages\pluggy.py:264:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_getframe'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
return _wrapped_call(hook_impl.function(*args), self.execute)
> res = hook_impl.function(*args)
..\_pytest\vendored_packages\pluggy.py:596:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
item = <AppTestMethod 'test_getframe'>
@pytest.hookimpl(tryfirst=True)
def pytest_runtest_setup(item):
if isinstance(item, pytest.Function):
config = item.config
if get_marker(item, name='pypy_only'):
if config.applevel is not None and not config.applevel.is_pypy:
pytest.skip('PyPy-specific test')
appclass = item.getparent(pytest.Class)
if appclass is not None:
from pypy.tool.pytest.objspace import gettestobjspace
# Make cls.space and cls.runappdirect available in tests.
spaceconfig = getattr(appclass.obj, 'spaceconfig', {})
> appclass.obj.space = gettestobjspace(**spaceconfig)
conftest.py:259:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]}
config = <rpython.config.config.Config object at 0x000001b4ea739ad0>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001b4ea739ad0>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001b4ea739ad0>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000001b4ea739ad0>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000001b4e9e457a0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000001b4e6e3e138>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe499540a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49954060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49953ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000001b4e4c05328>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x000001b4e9e54090>, <W_TypeObject 'GenericAlias' at 0x1b4e75c8560>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b4e74472f0>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b4e74472f0>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b4e74472f0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b4e74472f0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b4e5c9c3e0>>
w_obj = <W_TypeObject 'ellipsis' at 0x1b4e74472f0>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x1b4e74472f0>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b4e5c9c3e0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x1b4e74472f0>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b4e5c9c3e0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b4e5c9c3e0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b4e5c9c3e0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'
..\rpython\rtyper\lltypesystem\lltype.py:1270: AttributeError
_______________ ERROR at setup of AppTestCall.test_getbuiltins ________________
self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'>
func = <function <lambda> at 0x000001b4ea369bc8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=item, **kwds), when=when)
..\_pytest\runner.py:138:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_HookCaller 'pytest_runtest_setup'>
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_getbuiltins'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_getbuiltins'>}
def __call__(self, **kwargs):
assert not self.is_historic()
> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
..\_pytest\vendored_packages\pluggy.py:724:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.config.PytestPluginManager object at 0x000001b4e01e3408>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001b4e800a460>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001b4e06a6660>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001b4e06a66a0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_getbuiltins'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_getbuiltins'>}
def _hookexec(self, hook, methods, kwargs):
# called from all hookcaller instances.
# enable_tracing will set its own wrapping function at self._inner_hookexec
> return self._inner_hookexec(hook, methods, kwargs)
..\_pytest\vendored_packages\pluggy.py:338:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001b4e800a460>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000001b4e06a6660>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000001b4e06a66a0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_getbuiltins'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_getbuiltins'>}
self._inner_hookexec = lambda hook, methods, kwargs: \
> _MultiCall(methods, kwargs, hook.spec_opts).execute()
..\_pytest\vendored_packages\pluggy.py:333:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_getbuiltins'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
> return _wrapped_call(hook_impl.function(*args), self.execute)
..\_pytest\vendored_packages\pluggy.py:595:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
wrap_controller = <generator object pytest_runtest_setup at 0x000001b4e5737ba0>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...etbuiltins'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>>
def _wrapped_call(wrap_controller, func):
""" Wrap calling to a function with a generator which needs to yield
exactly once. The yield point will trigger calling the wrapped function
and return its _CallOutcome to the yield point. The generator then needs
to finish (raise StopIteration) in order for the wrapped call to complete.
"""
try:
next(wrap_controller) # first yield
except StopIteration:
_raise_wrapfail(wrap_controller, "did not yield")
call_outcome = _CallOutcome(func)
try:
wrap_controller.send(call_outcome)
_raise_wrapfail(wrap_controller, "has second yield")
except StopIteration:
pass
> return call_outcome.get_result()
..\_pytest\vendored_packages\pluggy.py:253:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001b4e9c0d4e0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000001b4e9c0d4e0>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...etbuiltins'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>>
def __init__(self, func):
try:
> self.result = func()
..\_pytest\vendored_packages\pluggy.py:264:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_getbuiltins'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
return _wrapped_call(hook_impl.function(*args), self.execute)
> res = hook_impl.function(*args)
..\_pytest\vendored_packages\pluggy.py:596:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
item = <AppTestMethod 'test_getbuiltins'>
@pytest.hookimpl(tryfirst=True)
def pytest_runtest_setup(item):
if isinstance(item, pytest.Function):
config = item.config
if get_marker(item, name='pypy_only'):
if config.applevel is not None and not config.applevel.is_pypy:
pytest.skip('PyPy-specific test')
appclass = item.getparent(pytest.Class)
if appclass is not None:
from pypy.tool.pytest.objspace import gettestobjspace
# Make cls.space and cls.runappdirect available in tests.
spaceconfig = getattr(appclass.obj, 'spaceconfig', {})
> appclass.obj.space = gettestobjspace(**spaceconfig)
conftest.py:259:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]}
config = <rpython.config.config.Config object at 0x000001b4e9c4bb08>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001b4e9c4bb08>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001b4e9c4bb08>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000001b4e9c4bb08>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000001b4ea5805a0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000001b4e1498250>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe499540a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49954060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49953ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000001b4e4c05328>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x000001b4ea5280c8>, <W_TypeObject 'GenericAlias' at 0x1b4e75c9b08>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b4e719e250>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b4e719e250>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b4e719e250>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b4e719e250>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b4e5c9e060>>
w_obj = <W_TypeObject 'ellipsis' at 0x1b4e719e250>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x1b4e719e250>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b4e5c9e060>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x1b4e719e250>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b4e5c9e060>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b4e5c9e060>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b4e5c9e060>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E 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 703.05 seconds ==========================
++ 06:38:12 starting module/cpyext/test/test_funcobject.py [67 started in total]
__ module/cpyext/test/test_frameobject.py [64 done in total, somefailed=True] _
[platform:msg] Updated environment with vsver 160, using x64 True
[platform:msg] Updated environment with vsver 160, using x64 True
============================= test session starts =============================
platform win32 -- Python 2.7.18[pypy-7.3.18-alpha], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('d:\\pypy_stuff\\buildbot64\\slave\\own-win-x86-64\\build\\pypy\\.hypothesis\\examples')
pytest-2.9.2 from d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build\pytest.pyc
rootdir: d:\pypy_stuff\buildbot64\slave\own-win-x86-64\build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 5 items
module\cpyext\test\test_frameobject.py EEEEE
=================================== ERRORS ====================================
____________ ERROR at setup of AppTestFrameObject.test_forge_frame ____________
self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'>
func = <function <lambda> at 0x00000137861639e8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=item, **kwds), when=when)
..\_pytest\runner.py:138:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_HookCaller 'pytest_runtest_setup'>
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_forge_frame'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_forge_frame'>}
def __call__(self, **kwargs):
assert not self.is_historic()
> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
..\_pytest\vendored_packages\pluggy.py:724:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.config.PytestPluginManager object at 0x00000137fe2e1440>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000137868061a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000137fe7a66a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000137fe7a66e0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_forge_frame'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_forge_frame'>}
def _hookexec(self, hook, methods, kwargs):
# called from all hookcaller instances.
# enable_tracing will set its own wrapping function at self._inner_hookexec
> return self._inner_hookexec(hook, methods, kwargs)
..\_pytest\vendored_packages\pluggy.py:338:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000137868061a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000137fe7a66a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000137fe7a66e0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_forge_frame'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_forge_frame'>}
self._inner_hookexec = lambda hook, methods, kwargs: \
> _MultiCall(methods, kwargs, hook.spec_opts).execute()
..\_pytest\vendored_packages\pluggy.py:333:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_forge_frame'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
> return _wrapped_call(hook_impl.function(*args), self.execute)
..\_pytest\vendored_packages\pluggy.py:595:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
wrap_controller = <generator object pytest_runtest_setup at 0x000001378682aa20>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...orge_frame'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>>
def _wrapped_call(wrap_controller, func):
""" Wrap calling to a function with a generator which needs to yield
exactly once. The yield point will trigger calling the wrapped function
and return its _CallOutcome to the yield point. The generator then needs
to finish (raise StopIteration) in order for the wrapped call to complete.
"""
try:
next(wrap_controller) # first yield
except StopIteration:
_raise_wrapfail(wrap_controller, "did not yield")
call_outcome = _CallOutcome(func)
try:
wrap_controller.send(call_outcome)
_raise_wrapfail(wrap_controller, "has second yield")
except StopIteration:
pass
> return call_outcome.get_result()
..\_pytest\vendored_packages\pluggy.py:253:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000137864b3f20>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000137864b3f20>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...orge_frame'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>>
def __init__(self, func):
try:
> self.result = func()
..\_pytest\vendored_packages\pluggy.py:264:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_forge_frame'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
return _wrapped_call(hook_impl.function(*args), self.execute)
> res = hook_impl.function(*args)
..\_pytest\vendored_packages\pluggy.py:596:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
item = <AppTestMethod 'test_forge_frame'>
@pytest.hookimpl(tryfirst=True)
def pytest_runtest_setup(item):
if isinstance(item, pytest.Function):
config = item.config
if get_marker(item, name='pypy_only'):
if config.applevel is not None and not config.applevel.is_pypy:
pytest.skip('PyPy-specific test')
appclass = item.getparent(pytest.Class)
if appclass is not None:
from pypy.tool.pytest.objspace import gettestobjspace
# Make cls.space and cls.runappdirect available in tests.
spaceconfig = getattr(appclass.obj, 'spaceconfig', {})
> appclass.obj.space = gettestobjspace(**spaceconfig)
conftest.py:259:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]}
config = <rpython.config.config.Config object at 0x00000137857ad210>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00000137857ad210>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00000137857ad210>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00000137857ad210>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000013785bb8860>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000013785c63da8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe499930a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49993060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49992ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000001378234c4b8>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x00000137857ad788>, <W_TypeObject 'GenericAlias' at 0x137855edbe8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x137872205d0>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x137872205d0>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x137872205d0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x137872205d0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x13784ef9650>>
w_obj = <W_TypeObject 'ellipsis' at 0x137872205d0>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x137872205d0>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x13784ef9650>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x137872205d0>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x13784ef9650>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x13784ef9650>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x13784ef9650>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'
..\rpython\rtyper\lltypesystem\lltype.py:1270: AttributeError
_________ ERROR at setup of AppTestFrameObject.test_forge_frame_newer _________
self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'>
func = <function <lambda> at 0x0000013788d512e0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=item, **kwds), when=when)
..\_pytest\runner.py:138:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_HookCaller 'pytest_runtest_setup'>
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_forge_frame_newer'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_forge_frame_newer'>}
def __call__(self, **kwargs):
assert not self.is_historic()
> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
..\_pytest\vendored_packages\pluggy.py:724:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.config.PytestPluginManager object at 0x00000137fe2e1440>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000137868061a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000137fe7a66a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000137fe7a66e0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_forge_frame_newer'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_forge_frame_newer'>}
def _hookexec(self, hook, methods, kwargs):
# called from all hookcaller instances.
# enable_tracing will set its own wrapping function at self._inner_hookexec
> return self._inner_hookexec(hook, methods, kwargs)
..\_pytest\vendored_packages\pluggy.py:338:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000137868061a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000137fe7a66a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000137fe7a66e0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_forge_frame_newer'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_forge_frame_newer'>}
self._inner_hookexec = lambda hook, methods, kwargs: \
> _MultiCall(methods, kwargs, hook.spec_opts).execute()
..\_pytest\vendored_packages\pluggy.py:333:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_forge_frame_newer'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
> return _wrapped_call(hook_impl.function(*args), self.execute)
..\_pytest\vendored_packages\pluggy.py:595:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
wrap_controller = <generator object pytest_runtest_setup at 0x00000137897b84a8>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...rame_newer'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>>
def _wrapped_call(wrap_controller, func):
""" Wrap calling to a function with a generator which needs to yield
exactly once. The yield point will trigger calling the wrapped function
and return its _CallOutcome to the yield point. The generator then needs
to finish (raise StopIteration) in order for the wrapped call to complete.
"""
try:
next(wrap_controller) # first yield
except StopIteration:
_raise_wrapfail(wrap_controller, "did not yield")
call_outcome = _CallOutcome(func)
try:
wrap_controller.send(call_outcome)
_raise_wrapfail(wrap_controller, "has second yield")
except StopIteration:
pass
> return call_outcome.get_result()
..\_pytest\vendored_packages\pluggy.py:253:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000137896c8be0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000137896c8be0>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...rame_newer'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>>
def __init__(self, func):
try:
> self.result = func()
..\_pytest\vendored_packages\pluggy.py:264:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_forge_frame_newer'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
return _wrapped_call(hook_impl.function(*args), self.execute)
> res = hook_impl.function(*args)
..\_pytest\vendored_packages\pluggy.py:596:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
item = <AppTestMethod 'test_forge_frame_newer'>
@pytest.hookimpl(tryfirst=True)
def pytest_runtest_setup(item):
if isinstance(item, pytest.Function):
config = item.config
if get_marker(item, name='pypy_only'):
if config.applevel is not None and not config.applevel.is_pypy:
pytest.skip('PyPy-specific test')
appclass = item.getparent(pytest.Class)
if appclass is not None:
from pypy.tool.pytest.objspace import gettestobjspace
# Make cls.space and cls.runappdirect available in tests.
spaceconfig = getattr(appclass.obj, 'spaceconfig', {})
> appclass.obj.space = gettestobjspace(**spaceconfig)
conftest.py:259:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]}
config = <rpython.config.config.Config object at 0x0000013789771e88>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000013789771e88>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000013789771e88>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000013789771e88>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000013789aba020>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000013789b54ec8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe499930a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49993060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49992ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000001378234c4b8>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x00000137897cc5d0>, <W_TypeObject 'GenericAlias' at 0x13784bd3910>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x13783e7fd38>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x13783e7fd38>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x13783e7fd38>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x13783e7fd38>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x13784efcbc0>>
w_obj = <W_TypeObject 'ellipsis' at 0x13783e7fd38>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x13783e7fd38>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x13784efcbc0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x13783e7fd38>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x13784efcbc0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x13784efcbc0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x13784efcbc0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'
..\rpython\rtyper\lltypesystem\lltype.py:1270: AttributeError
__________ ERROR at setup of AppTestFrameObject.test_traceback_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 0x00000137842c63e0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=item, **kwds), when=when)
..\_pytest\runner.py:138:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_HookCaller 'pytest_runtest_setup'>
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_traceback_check'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_traceback_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 0x00000137fe2e1440>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000137868061a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000137fe7a66a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000137fe7a66e0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_traceback_check'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_traceback_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 0x00000137868061a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000137fe7a66a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000137fe7a66e0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_traceback_check'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_traceback_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_traceback_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 0x00000137839c78f8>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...back_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 0x00000137895c5da0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000137895c5da0>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...back_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_traceback_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_traceback_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 0x00000137895dbc20>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00000137895dbc20>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00000137895dbc20>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00000137895dbc20>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000013788197020>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000013789b55ef8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe499530a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49953060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49952ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000001378234c4b8>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x0000013788e961e0>, <W_TypeObject 'GenericAlias' at 0x137852dacd0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x137842df050>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x137842df050>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x137842df050>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x137842df050>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x13784efa820>>
w_obj = <W_TypeObject 'ellipsis' at 0x137842df050>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x137842df050>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x13784efa820>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x137842df050>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x13784efa820>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x13784efa820>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x13784efa820>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'
..\rpython\rtyper\lltypesystem\lltype.py:1270: AttributeError
______________ ERROR at setup of AppTestFrameObject.test_get_xxx ______________
self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'>
func = <function <lambda> at 0x0000013786ca5790>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=item, **kwds), when=when)
..\_pytest\runner.py:138:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_HookCaller 'pytest_runtest_setup'>
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_get_xxx'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_get_xxx'>}
def __call__(self, **kwargs):
assert not self.is_historic()
> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
..\_pytest\vendored_packages\pluggy.py:724:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.config.PytestPluginManager object at 0x00000137fe2e1440>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000137868061a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000137fe7a66a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000137fe7a66e0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_get_xxx'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_get_xxx'>}
def _hookexec(self, hook, methods, kwargs):
# called from all hookcaller instances.
# enable_tracing will set its own wrapping function at self._inner_hookexec
> return self._inner_hookexec(hook, methods, kwargs)
..\_pytest\vendored_packages\pluggy.py:338:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000137868061a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000137fe7a66a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000137fe7a66e0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_get_xxx'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_get_xxx'>}
self._inner_hookexec = lambda hook, methods, kwargs: \
> _MultiCall(methods, kwargs, hook.spec_opts).execute()
..\_pytest\vendored_packages\pluggy.py:333:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_get_xxx'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
> return _wrapped_call(hook_impl.function(*args), self.execute)
..\_pytest\vendored_packages\pluggy.py:595:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
wrap_controller = <generator object pytest_runtest_setup at 0x000001378565c9f8>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...st_get_xxx'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>>
def _wrapped_call(wrap_controller, func):
""" Wrap calling to a function with a generator which needs to yield
exactly once. The yield point will trigger calling the wrapped function
and return its _CallOutcome to the yield point. The generator then needs
to finish (raise StopIteration) in order for the wrapped call to complete.
"""
try:
next(wrap_controller) # first yield
except StopIteration:
_raise_wrapfail(wrap_controller, "did not yield")
call_outcome = _CallOutcome(func)
try:
wrap_controller.send(call_outcome)
_raise_wrapfail(wrap_controller, "has second yield")
except StopIteration:
pass
> return call_outcome.get_result()
..\_pytest\vendored_packages\pluggy.py:253:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000137891fe120>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000137891fe120>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...st_get_xxx'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>>
def __init__(self, func):
try:
> self.result = func()
..\_pytest\vendored_packages\pluggy.py:264:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_get_xxx'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
return _wrapped_call(hook_impl.function(*args), self.execute)
> res = hook_impl.function(*args)
..\_pytest\vendored_packages\pluggy.py:596:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
item = <AppTestMethod 'test_get_xxx'>
@pytest.hookimpl(tryfirst=True)
def pytest_runtest_setup(item):
if isinstance(item, pytest.Function):
config = item.config
if get_marker(item, name='pypy_only'):
if config.applevel is not None and not config.applevel.is_pypy:
pytest.skip('PyPy-specific test')
appclass = item.getparent(pytest.Class)
if appclass is not None:
from pypy.tool.pytest.objspace import gettestobjspace
# Make cls.space and cls.runappdirect available in tests.
spaceconfig = getattr(appclass.obj, 'spaceconfig', {})
> appclass.obj.space = gettestobjspace(**spaceconfig)
conftest.py:259:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]}
config = <rpython.config.config.Config object at 0x000001378795d210>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001378795d210>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001378795d210>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000001378795d210>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000013787eb7060>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00000137833bd328>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe499930a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49993060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49992ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000001378234c4b8>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x000001378795d788>, <W_TypeObject 'GenericAlias' at 0x13785734410>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x137851f7360>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x137851f7360>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x137851f7360>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x137851f7360>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x13784ef9d70>>
w_obj = <W_TypeObject 'ellipsis' at 0x137851f7360>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x137851f7360>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x13784ef9d70>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x137851f7360>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x13784ef9d70>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x13784ef9d70>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x13784ef9d70>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'
..\rpython\rtyper\lltypesystem\lltype.py:1270: AttributeError
___________ ERROR at setup of AppTestFrameObject.test_frame_getvar ____________
self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'>
func = <function <lambda> at 0x00000137899c7010>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=item, **kwds), when=when)
..\_pytest\runner.py:138:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_HookCaller 'pytest_runtest_setup'>
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_frame_getvar'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_frame_getvar'>}
def __call__(self, **kwargs):
assert not self.is_historic()
> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
..\_pytest\vendored_packages\pluggy.py:724:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.config.PytestPluginManager object at 0x00000137fe2e1440>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000137868061a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000137fe7a66a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000137fe7a66e0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_frame_getvar'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_frame_getvar'>}
def _hookexec(self, hook, methods, kwargs):
# called from all hookcaller instances.
# enable_tracing will set its own wrapping function at self._inner_hookexec
> return self._inner_hookexec(hook, methods, kwargs)
..\_pytest\vendored_packages\pluggy.py:338:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000137868061a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000137fe7a66a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000137fe7a66e0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_frame_getvar'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_frame_getvar'>}
self._inner_hookexec = lambda hook, methods, kwargs: \
> _MultiCall(methods, kwargs, hook.spec_opts).execute()
..\_pytest\vendored_packages\pluggy.py:333:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_frame_getvar'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
> return _wrapped_call(hook_impl.function(*args), self.execute)
..\_pytest\vendored_packages\pluggy.py:595:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
wrap_controller = <generator object pytest_runtest_setup at 0x00000137898f3ab0>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ame_getvar'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>>
def _wrapped_call(wrap_controller, func):
""" Wrap calling to a function with a generator which needs to yield
exactly once. The yield point will trigger calling the wrapped function
and return its _CallOutcome to the yield point. The generator then needs
to finish (raise StopIteration) in order for the wrapped call to complete.
"""
try:
next(wrap_controller) # first yield
except StopIteration:
_raise_wrapfail(wrap_controller, "did not yield")
call_outcome = _CallOutcome(func)
try:
wrap_controller.send(call_outcome)
_raise_wrapfail(wrap_controller, "has second yield")
except StopIteration:
pass
> return call_outcome.get_result()
..\_pytest\vendored_packages\pluggy.py:253:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000137893869a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000137893869a0>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ame_getvar'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>>
def __init__(self, func):
try:
> self.result = func()
..\_pytest\vendored_packages\pluggy.py:264:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_frame_getvar'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
return _wrapped_call(hook_impl.function(*args), self.execute)
> res = hook_impl.function(*args)
..\_pytest\vendored_packages\pluggy.py:596:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
item = <AppTestMethod 'test_frame_getvar'>
@pytest.hookimpl(tryfirst=True)
def pytest_runtest_setup(item):
if isinstance(item, pytest.Function):
config = item.config
if get_marker(item, name='pypy_only'):
if config.applevel is not None and not config.applevel.is_pypy:
pytest.skip('PyPy-specific test')
appclass = item.getparent(pytest.Class)
if appclass is not None:
from pypy.tool.pytest.objspace import gettestobjspace
# Make cls.space and cls.runappdirect available in tests.
spaceconfig = getattr(appclass.obj, 'spaceconfig', {})
> appclass.obj.space = gettestobjspace(**spaceconfig)
conftest.py:259:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]}
config = <rpython.config.config.Config object at 0x000001378933a0c8>
key = (((True, True, True, False, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', True, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001378933a0c8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000001378933a0c8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000001378933a0c8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace\std\objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter\baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000001378939d160>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module\cpyext\state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module\cpyext\api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00000137881ff248>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module\cpyext\api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe499930a0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7ffe49993060>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7ffe49992ec0>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000001378234c4b8>, W_BoolObject(True), W_BoolObject(False), <p... <pypy.interpreter.special.Ellipsis object at 0x000001378933a640>, <W_TypeObject 'GenericAlias' at 0x137863468a8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module\cpyext\api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x137845a4170>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module\cpyext\pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x137845a4170>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x137845a4170>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module\cpyext\pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x137845a4170>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module\cpyext\pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x13784efb2d0>>
w_obj = <W_TypeObject 'ellipsis' at 0x137845a4170>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module\cpyext\pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x137845a4170>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x13784efb2d0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module\cpyext\pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x137845a4170>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x13784efb2d0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
..\rpython\rlib\rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x13784efb2d0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
..\rpython\rlib\rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x13784efb2d0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'
..\rpython\rtyper\lltypesystem\lltype.py:1270: AttributeError
========================== 5 error in 183.73 seconds ==========================
command interrupted, attempting to kill
program finished with exit code 1
elapsedTime=4171.496000