Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segmentation Fault when trying to access an object's property #17

Closed
DillanCMills opened this issue Sep 23, 2021 · 22 comments
Closed

Segmentation Fault when trying to access an object's property #17

DillanCMills opened this issue Sep 23, 2021 · 22 comments

Comments

@DillanCMills
Copy link

I am working with the MikePopoloski/slang library. I am trying to walk an AST generated after compiling some code with it. If I call the built-in functions, it is able to walk the tree completely, so I know all the data is there and able to be referenced. When I attempt to walk the tree manually, I get a couple layers deep before hitting a segfault when attempting to check a simple string_view attached to an object. Unfortunately, creating a standalone reproducer of this would be challenging.

https://github.com/MikePopoloski/slang/blob/3ae64c22f38ce0797b96c41041d1f75c00bf0377/include/slang/symbols/InstanceSymbols.h#L99

This is the object I eventually crash on. The hierarchy would be:
Compilation > DesignTree > Instances[0] > InstanceSymbol > InstancyBodySymbol

Then, when I try to call str(body.name), I get a stack trace. Most of the information looks pretty generic to me, but here it is anyway:

segmentation fault
*** Break *** segmentation violation
#0  0x00007fd0116dc437 in __GI___waitpid (pid=11716, stat_loc=stat_loc
entry=0x7ffdaa45d158, options=options
entry=0) at ../sysdeps/unix/sysv/linux/waitpid.c:30
#1  0x00007fd01165a5df in do_system (line=<optimized out>) at ../sysdeps/posix/system.c:149
#2  0x00007fd010e3b355 in CppyyLegacy::TUnixSystem::StackTrace() () from /home/dillan/git_projects/svls/env_dbg/lib/python3.9/site-packages/cppyy_backend/lib/libCoreLegacy.so
#3  0x00007fd00c5a6d08 in (anonymous namespace)::do_trace (sig=1) at src/clingwrapper.cxx:199
#4  (anonymous namespace)::TExceptionHandlerImp::HandleException (this=<optimized out>, sig=1) at src/clingwrapper.cxx:212
#5  0x00007fd010e39e61 in CppyyLegacy::TUnixSystem::DispatchSignals(CppyyLegacy::ESignals) () from /home/dillan/git_projects/svls/env_dbg/lib/python3.9/site-packages/cppyy_backend/lib/libCoreLegacy.so
#6  <signal handler called>
#7  0x00007fd009025a7e in ska::fibonacci_hash_policy::index_for_hash (this=0xffffffff0000032e, hash=94329315036496) at /home/dillan/git_projects/svls/external/slang/source/../external/flat_hash_map.hpp:1274
#8  ska::detailv3::sherwood_v3_table<std::pair<void const*, nonstd::span_lite::span<slang::AttributeSymbol const* const, 18446744073709551615ul> >, void const*, std::hash<void const*>, ska::detailv3::KeyOrValueHasher<void const*, std::pair<void const*, nonstd::span_lite::span<slang::AttributeSymbol const* const, 18446744073709551615ul> >, std::hash<void const*> >, std::equal_to<void const*>, ska::detailv3::KeyOrValueEquality<void const*, std::pair<void const*, nonstd::span_lite::span<slang::AttributeSymbol const* const, 18446744073709551615ul> >, std::equal_to<void const*> >, std::allocator<std::pair<void const*, nonstd::span_lite::span<slang::AttributeSymbol const* const, 18446744073709551615ul> > >, std::allocator<ska::detailv3::sherwood_v3_entry<std::pair<void const*, nonstd::span_lite::span<slang::AttributeSymbol const* const, 18446744073709551615ul> > > > >::find (this=0xffffffff0000031e, key=<optimized out>) at /home/dillan/git_projects/svls/external/slang/source/../external/flat_hash_map.hpp:542
#9  ska::detailv3::sherwood_v3_table<std::pair<void const*, nonstd::span_lite::span<slang::AttributeSymbol const* const, 18446744073709551615ul> >, void const*, std::hash<void const*>, ska::detailv3::KeyOrValueHasher<void const*, std::pair<void const*, nonstd::span_lite::span<slang::AttributeSymbol const* const, 18446744073709551615ul> >, std::hash<void const*> >, std::equal_to<void const*>, ska::detailv3::KeyOrValueEquality<void const*, std::pair<void const*, nonstd::span_lite::span<slang::AttributeSymbol const* const, 18446744073709551615ul> >, std::equal_to<void const*> >, std::allocator<std::pair<void const*, nonstd::span_lite::span<slang::AttributeSymbol const* const, 18446744073709551615ul> > >, std::allocator<ska::detailv3::sherwood_v3_entry<std::pair<void const*, nonstd::span_lite::span<slang::AttributeSymbol const* const, 18446744073709551615ul> > > > >::find (this=0xffffffff0000031e, key=<optimized out>) at /home/dillan/git_projects/svls/external/slang/source/../external/flat_hash_map.hpp:553
#10 slang::Compilation::getAttributes (this=0xffffffff00000006, ptr=<optimized out>) at /home/dillan/git_projects/svls/external/slang/source/compilation/Compilation.cpp:617
#11 slang::Compilation::getAttributes (this=0xffffffff00000006, symbol=...) at /home/dillan/git_projects/svls/external/slang/source/compilation/Compilation.cpp:605
#12 0x00007fd0099fd013 in ?? ()
#13 0x00007ffdaa45fc80 in ?? ()
#14 0x00007fd00c5a68de in WrapperCall (method=94329305792864, nargs=1, args_=0x55cac1c305a0, self=0xffffffff00000006, result=0x55cac1c305a0) at src/clingwrapper.cxx:848
#15 0x00007fd00c5a7646 in Cppyy::CallO (method=method
entry=94329305792864, self=self
entry=0xffffffff00000006, nargs=1, args=0x7ffdaa45fc80, result_type=result_type
entry=89) at src/clingwrapper.cxx:957
#16 0x00007fd00a409110 in GILCallO (klass=89, ctxt=0x7ffdaa45fc60, self=0xffffffff00000006, method=94329305792864) at src/CallContext.h:100
#17 GILCallO (klass=89, ctxt=0x7ffdaa45fc60, self=0xffffffff00000006, method=94329305792864) at src/Executors.cxx:80
#18 CPyCppyy::(anonymous namespace)::InstanceExecutor::Execute (this=0x55cac1c49af0, method=94329305792864, self=0xffffffff00000006, ctxt=0x7ffdaa45fc60) at src/Executors.cxx:592
#19 0x00007fd00a3dcc79 in CPyCppyy::CPPMethod::ExecuteFast (ctxt=<optimized out>, offset=<optimized out>, self=<optimized out>, this=0x55cac0c38370) at src/CPPMethod.cxx:853
#20 CPyCppyy::CPPMethod::Execute (this=0x55cac0c38370, self=<optimized out>, offset=<optimized out>, ctxt=<optimized out>) at src/CPPMethod.cxx:853
#21 0x00007fd00a3dcf96 in CPyCppyy::CPPMethod::Call (this=0x55cac0c38370, self=
0x7fd009bd3990: 0x7fd009a9a600, args=<optimized out>, nargsf=<optimized out>, kwds=<optimized out>, ctxt=0x7ffdaa45fc60) at src/CPPMethod.cxx:913
#22 0x00007fd00a3e15c0 in CPyCppyy::(anonymous namespace)::mp_vectorcall (pymeth=0x7fd009bd3980, args=0x7fd011243970, nargsf=9223372036854775810, kwds=0x0) at src/CPPOverload.cxx:708
#23 0x000055cab73c4141 in _PyObject_VectorcallTstate (kwnames=0x0, nargsf=<optimized out>, args=0x7fd011243970, callable=0x7fd009bd3980, tstate=0x55cab9289250) at ./Include/cpython/abstract.h:118
#24 PyObject_Vectorcall (kwnames=0x0, nargsf=<optimized out>, args=0x7fd011243970, callable=0x7fd009bd3980) at ./Include/cpython/abstract.h:127
#25 call_function (kwnames=0x0, oparg=<optimized out>, pp_stack=<synthetic pointer>, tstate=<optimized out>) at Python/ceval.c:5075
#26 _PyEval_EvalFrameDefault (tstate=<optimized out>, f=<optimized out>, throwflag=<optimized out>) at Python/ceval.c:3504
#27 0x000055cab748a055 in _PyEval_EvalFrame (throwflag=0, f=0x7fd011243800, tstate=0x55cab9289250) at ./Include/internal/pycore_ceval.h:40
#28 _PyEval_EvalCode (tstate=0x55cab9289250, _co=_co
entry=0x7fd009a99500, globals=globals
entry=0x7fd011261340, locals=locals
entry=0x7fd011261340, args=args
entry=0x0, argcount=argcount
entry=0, kwnames=0x0, kwargs=0x0, kwcount=0, kwstep=2, defs=0x0, defcount=0, kwdefs=0x0, closure=0x0, name=0x0, qualname=0x0) at Python/ceval.c:4327
#29 0x000055cab748a386 in _PyEval_EvalCodeWithName (qualname=0x0, name=0x0, closure=0x0, kwdefs=0x0, defcount=0, defs=0x0, kwstep=2, kwcount=0, kwargs=0x0, kwnames=0x0, argcount=0, args=0x0, locals=0x7fd011261340, globals=0x7fd011261340, _co=0x7fd009a99500) at Python/ceval.c:4359
#30 PyEval_EvalCodeEx (closure=0x0, kwdefs=0x0, defcount=0, defs=0x0, kwcount=0, kws=0x0, argcount=0, args=0x0, locals=0x7fd011261340, globals=0x7fd011261340, _co=0x7fd009a99500) at Python/ceval.c:4375
#31 PyEval_EvalCode (co=co
entry=0x7fd009a99500, globals=globals
entry=0x7fd011261340, locals=locals
entry=0x7fd011261340) at Python/ceval.c:826
#32 0x000055cab74c7937 in run_eval_code_obj (locals=0x7fd011261340, globals=0x7fd011261340, co=0x7fd009a99500, tstate=0x55cab9289250) at Python/pythonrun.c:1219
#33 run_mod (mod=mod
entry=0x55cab93c0028, filename=filename
entry=0x7fd0111ecaf0, globals=0x7fd011261340, locals=0x7fd011261340, flags=flags
entry=0x7ffdaa460168, arena=arena
entry=0x7fd0111fcbb0) at Python/pythonrun.c:1240
#34 0x000055cab74c90c0 in PyRun_InteractiveOneObjectEx (fp=fp
entry=0x7fd0117d1a00 <_IO_2_1_stdin_>, filename=filename
entry=0x7fd0111ecaf0, flags=flags
entry=0x7ffdaa460168) at Python/pythonrun.c:273
#35 0x000055cab74c9366 in PyRun_InteractiveLoopFlags (fp=fp
entry=0x7fd0117d1a00 <_IO_2_1_stdin_>, filename_str=filename_str
entry=0x55cab75cf132 "<stdin>", flags=flags
entry=0x7ffdaa460168) at Python/pythonrun.c:126
#36 0x000055cab74c9cbe in PyRun_AnyFileExFlags (fp=0x7fd0117d1a00 <_IO_2_1_stdin_>, filename=filename
entry=0x55cab75cf132 "<stdin>", closeit=closeit
entry=0, flags=flags
entry=0x7ffdaa460168) at Python/pythonrun.c:85
#37 0x000055cab73cbc59 in pymain_run_stdin (cf=0x7ffdaa460168, config=0x55cab9287b40) at Modules/main.c:512
#38 pymain_run_python (exitcode=exitcode
entry=0x7ffdaa460290) at Modules/main.c:601
#39 0x000055cab73cc038 in Py_RunMain () at Modules/main.c:677
#40 pymain_main (args=0x7ffdaa460250) at Modules/main.c:707
#41 Py_BytesMain (argc=<optimized out>, argv=<optimized out>) at Modules/main.c:731
#42 0x00007fd01163a09b in __libc_start_main (main=0x55cab73bf6d0 <main>, argc=1, argv=0x7ffdaa460398, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7ffdaa460388) at ../csu/libc-start.c:308
#43 0x000055cab73cacfa in _start () at Python/ceval.c:5185
 *** Break *** segmentation violation
#0  0x00007fd0116dc437 in __GI___waitpid (pid=11980, stat_loc=stat_loc
entry=0x7ffdaa45d158, options=options
entry=0) at ../sysdeps/unix/sysv/linux/waitpid.c:30
#1  0x00007fd01165a5df in do_system (line=<optimized out>) at ../sysdeps/posix/system.c:149
#2  0x00007fd010e3b355 in CppyyLegacy::TUnixSystem::StackTrace() () from /home/dillan/git_projects/svls/env_dbg/lib/python3.9/site-packages/cppyy_backend/lib/libCoreLegacy.so
#3  0x00007fd00c5a6b78 in (anonymous namespace)::do_trace (sig=1) at src/clingwrapper.cxx:199
#4  (anonymous namespace)::TExceptionHandlerImp::HandleException (this=<optimized out>, sig=1) at src/clingwrapper.cxx:218
#5  0x00007fd010e39e61 in CppyyLegacy::TUnixSystem::DispatchSignals(CppyyLegacy::ESignals) () from /home/dillan/git_projects/svls/env_dbg/lib/python3.9/site-packages/cppyy_backend/lib/libCoreLegacy.so
#6  <signal handler called>
#7  0x00007fd009025a7e in ska::fibonacci_hash_policy::index_for_hash (this=0xffffffff0000032e, hash=94329315036496) at /home/dillan/git_projects/svls/external/slang/source/../external/flat_hash_map.hpp:1274
#8  ska::detailv3::sherwood_v3_table<std::pair<void const*, nonstd::span_lite::span<slang::AttributeSymbol const* const, 18446744073709551615ul> >, void const*, std::hash<void const*>, ska::detailv3::KeyOrValueHasher<void const*, std::pair<void const*, nonstd::span_lite::span<slang::AttributeSymbol const* const, 18446744073709551615ul> >, std::hash<void const*> >, std::equal_to<void const*>, ska::detailv3::KeyOrValueEquality<void const*, std::pair<void const*, nonstd::span_lite::span<slang::AttributeSymbol const* const, 18446744073709551615ul> >, std::equal_to<void const*> >, std::allocator<std::pair<void const*, nonstd::span_lite::span<slang::AttributeSymbol const* const, 18446744073709551615ul> > >, std::allocator<ska::detailv3::sherwood_v3_entry<std::pair<void const*, nonstd::span_lite::span<slang::AttributeSymbol const* const, 18446744073709551615ul> > > > >::find (this=0xffffffff0000031e, key=<optimized out>) at /home/dillan/git_projects/svls/external/slang/source/../external/flat_hash_map.hpp:542
#9  ska::detailv3::sherwood_v3_table<std::pair<void const*, nonstd::span_lite::span<slang::AttributeSymbol const* const, 18446744073709551615ul> >, void const*, std::hash<void const*>, ska::detailv3::KeyOrValueHasher<void const*, std::pair<void const*, nonstd::span_lite::span<slang::AttributeSymbol const* const, 18446744073709551615ul> >, std::hash<void const*> >, std::equal_to<void const*>, ska::detailv3::KeyOrValueEquality<void const*, std::pair<void const*, nonstd::span_lite::span<slang::AttributeSymbol const* const, 18446744073709551615ul> >, std::equal_to<void const*> >, std::allocator<std::pair<void const*, nonstd::span_lite::span<slang::AttributeSymbol const* const, 18446744073709551615ul> > >, std::allocator<ska::detailv3::sherwood_v3_entry<std::pair<void const*, nonstd::span_lite::span<slang::AttributeSymbol const* const, 18446744073709551615ul> > > > >::find (this=0xffffffff0000031e, key=<optimized out>) at /home/dillan/git_projects/svls/external/slang/source/../external/flat_hash_map.hpp:553
#10 slang::Compilation::getAttributes (this=0xffffffff00000006, ptr=<optimized out>) at /home/dillan/git_projects/svls/external/slang/source/compilation/Compilation.cpp:617
#11 slang::Compilation::getAttributes (this=0xffffffff00000006, symbol=...) at /home/dillan/git_projects/svls/external/slang/source/compilation/Compilation.cpp:605
#12 0x00007fd0099fd013 in ?? ()
#13 0x00007ffdaa45fc80 in ?? ()
#14 0x00007fd00c5a68de in WrapperCall (method=94329305792864, nargs=1, args_=0x55cac1c305a0, self=0xffffffff00000006, result=0x55cac1c305a0) at src/clingwrapper.cxx:848
#15 0x00007fd00c5a7646 in Cppyy::CallO (method=method
entry=94329305792864, self=self
entry=0xffffffff00000006, nargs=1, args=0x7ffdaa45fc80, result_type=result_type
entry=89) at src/clingwrapper.cxx:957
#16 0x00007fd00a409110 in GILCallO (klass=89, ctxt=0x7ffdaa45fc60, self=0xffffffff00000006, method=94329305792864) at src/CallContext.h:100
#17 GILCallO (klass=89, ctxt=0x7ffdaa45fc60, self=0xffffffff00000006, method=94329305792864) at src/Executors.cxx:80
#18 CPyCppyy::(anonymous namespace)::InstanceExecutor::Execute (this=0x55cac1c49af0, method=94329305792864, self=0xffffffff00000006, ctxt=0x7ffdaa45fc60) at src/Executors.cxx:592
#19 0x00007fd00a3dcc79 in CPyCppyy::CPPMethod::ExecuteFast (ctxt=<optimized out>, offset=<optimized out>, self=<optimized out>, this=0x55cac0c38370) at src/CPPMethod.cxx:853
#20 CPyCppyy::CPPMethod::Execute (this=0x55cac0c38370, self=<optimized out>, offset=<optimized out>, ctxt=<optimized out>) at src/CPPMethod.cxx:853
#21 0x00007fd00a3dcf96 in CPyCppyy::CPPMethod::Call (this=0x55cac0c38370, self=
0x7fd009bd3990: 0x7fd009a9a600, args=<optimized out>, nargsf=<optimized out>, kwds=<optimized out>, ctxt=0x7ffdaa45fc60) at src/CPPMethod.cxx:913
#22 0x00007fd00a3e15c0 in CPyCppyy::(anonymous namespace)::mp_vectorcall (pymeth=0x7fd009bd3980, args=0x7fd011243970, nargsf=9223372036854775810, kwds=0x0) at src/CPPOverload.cxx:708
#23 0x000055cab73c4141 in _PyObject_VectorcallTstate (kwnames=0x0, nargsf=<optimized out>, args=0x7fd011243970, callable=0x7fd009bd3980, tstate=0x55cab9289250) at ./Include/cpython/abstract.h:118
#24 PyObject_Vectorcall (kwnames=0x0, nargsf=<optimized out>, args=0x7fd011243970, callable=0x7fd009bd3980) at ./Include/cpython/abstract.h:127
#25 call_function (kwnames=0x0, oparg=<optimized out>, pp_stack=<synthetic pointer>, tstate=<optimized out>) at Python/ceval.c:5075
#26 _PyEval_EvalFrameDefault (tstate=<optimized out>, f=<optimized out>, throwflag=<optimized out>) at Python/ceval.c:3504
#27 0x000055cab748a055 in _PyEval_EvalFrame (throwflag=0, f=0x7fd011243800, tstate=0x55cab9289250) at ./Include/internal/pycore_ceval.h:40
#28 _PyEval_EvalCode (tstate=0x55cab9289250, _co=_co
entry=0x7fd009a99500, globals=globals
entry=0x7fd011261340, locals=locals
entry=0x7fd011261340, args=args
entry=0x0, argcount=argcount
entry=0, kwnames=0x0, kwargs=0x0, kwcount=0, kwstep=2, defs=0x0, defcount=0, kwdefs=0x0, closure=0x0, name=0x0, qualname=0x0) at Python/ceval.c:4327
#29 0x000055cab748a386 in _PyEval_EvalCodeWithName (qualname=0x0, name=0x0, closure=0x0, kwdefs=0x0, defcount=0, defs=0x0, kwstep=2, kwcount=0, kwargs=0x0, kwnames=0x0, argcount=0, args=0x0, locals=0x7fd011261340, globals=0x7fd011261340, _co=0x7fd009a99500) at Python/ceval.c:4359
#30 PyEval_EvalCodeEx (closure=0x0, kwdefs=0x0, defcount=0, defs=0x0, kwcount=0, kws=0x0, argcount=0, args=0x0, locals=0x7fd011261340, globals=0x7fd011261340, _co=0x7fd009a99500) at Python/ceval.c:4375
#31 PyEval_EvalCode (co=co
entry=0x7fd009a99500, globals=globals
entry=0x7fd011261340, locals=locals
entry=0x7fd011261340) at Python/ceval.c:826
#32 0x000055cab74c7937 in run_eval_code_obj (locals=0x7fd011261340, globals=0x7fd011261340, co=0x7fd009a99500, tstate=0x55cab9289250) at Python/pythonrun.c:1219
#33 run_mod (mod=mod
entry=0x55cab93c0028, filename=filename
entry=0x7fd0111ecaf0, globals=0x7fd011261340, locals=0x7fd011261340, flags=flags
entry=0x7ffdaa460168, arena=arena
entry=0x7fd0111fcbb0) at Python/pythonrun.c:1240
#34 0x000055cab74c90c0 in PyRun_InteractiveOneObjectEx (fp=fp
entry=0x7fd0117d1a00 <_IO_2_1_stdin_>, filename=filename
entry=0x7fd0111ecaf0, flags=flags
entry=0x7ffdaa460168) at Python/pythonrun.c:273
#35 0x000055cab74c9366 in PyRun_InteractiveLoopFlags (fp=fp
entry=0x7fd0117d1a00 <_IO_2_1_stdin_>, filename_str=filename_str
entry=0x55cab75cf132 "<stdin>", flags=flags
entry=0x7ffdaa460168) at Python/pythonrun.c:126
#36 0x000055cab74c9cbe in PyRun_AnyFileExFlags (fp=0x7fd0117d1a00 <_IO_2_1_stdin_>, filename=filename
entry=0x55cab75cf132 "<stdin>", closeit=closeit
entry=0, flags=flags
entry=0x7ffdaa460168) at Python/pythonrun.c:85
#37 0x000055cab73cbc59 in pymain_run_stdin (cf=0x7ffdaa460168, config=0x55cab9287b40) at Modules/main.c:512
#38 pymain_run_python (exitcode=exitcode
entry=0x7ffdaa460290) at Modules/main.c:601
#39 0x000055cab73cc038 in Py_RunMain () at Modules/main.c:677
#40 pymain_main (args=0x7ffdaa460250) at Modules/main.c:707
#41 Py_BytesMain (argc=<optimized out>, argv=<optimized out>) at Modules/main.c:731
#42 0x00007fd01163a09b in __libc_start_main (main=0x55cab73bf6d0 <main>, argc=1, argv=0x7ffdaa460398, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7ffdaa460388) at ../csu/libc-start.c:308
#43 0x000055cab73cacfa in _start () at Python/ceval.c:5185

Debian 10, python 3.9.7 with debug options installed, cppyy 2.1.0

If you are feeling up to installing slang, I would be happy to assist and provide a reproducer. Otherwise, any help would be appreciated.

@DillanCMills
Copy link
Author

Sorry, that was the wrong stacktrace, although it has some interesting info actually, so I am not going to get rid of it. Here is the one for accessing the name field. The one above was for calling getAttributes.

segmentation fault
 *** Break *** segmentation violation
#0  0x00007ff33a0cc437 in __GI___waitpid (pid=13176, stat_loc=stat_loc
entry=0x7ffec545c5d8, options=options
entry=0) at ../sysdeps/unix/sysv/linux/waitpid.c:30
#1  0x00007ff33a04a5df in do_system (line=<optimized out>) at ../sysdeps/posix/system.c:149
#2  0x00007ff33982b355 in CppyyLegacy::TUnixSystem::StackTrace() () from /home/dillan/git_projects/svls/env_dbg/lib/python3.9/site-packages/cppyy_backend/lib/libCoreLegacy.so
#3  0x00007ff334f96d08 in (anonymous namespace)::do_trace (sig=1) at src/clingwrapper.cxx:199
#4  (anonymous namespace)::TExceptionHandlerImp::HandleException (this=<optimized out>, sig=1) at src/clingwrapper.cxx:212
#5  0x00007ff339829e61 in CppyyLegacy::TUnixSystem::DispatchSignals(CppyyLegacy::ESignals) () from /home/dillan/git_projects/svls/env_dbg/lib/python3.9/site-packages/cppyy_backend/lib/libCoreLegacy.so
#6  <signal handler called>
#7  __memmove_sse2_unaligned_erms () at ../sysdeps/x86_64/multiarch/memmove-vec-unaligned-erms.S:440
#8  0x00007ff339623998 in std::basic_streambuf<char, std::char_traits<char> >::xsputn(char const*, long) () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#9  0x00007ff339614b34 in std::basic_ostream<char, std::char_traits<char> >& std::__ostream_insert<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*, long) () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#10 0x00007ff332421023 in ?? ()
#11 0x00007ffec545f150 in ?? ()
#12 0x00007ff334f968de in WrapperCall (method=94414373789536, nargs=2, args_=0x7ffec545eee8, self=0x0, result=0x7ffec545eee8) at src/clingwrapper.cxx:848
#13 0x00007ff334f97413 in Cppyy::CallR (method=<optimized out>, self=<optimized out>, nargs=<optimized out>, args=<optimized out>) at src/clingwrapper.cxx:916
#14 0x00007ff332df71df in CPyCppyy::(anonymous namespace)::InstanceRefExecutor::Execute (this=0x55de8efc0710, method=<optimized out>, self=<optimized out>, ctxt=<optimized out>) at src/Executors.cxx:624
#15 0x00007ff332dccc79 in CPyCppyy::CPPMethod::ExecuteFast (ctxt=0x7ffec545f130, offset=0, self=0x0, this=0x55de8f40b540) at src/CPPMethod.cxx:853
#16 CPyCppyy::CPPMethod::Execute (this=this
entry=0x55de8f40b540, self=self
entry=0x0, offset=offset
entry=0, ctxt=ctxt
entry=0x7ffec545f130) at src/CPPMethod.cxx:853
#17 0x00007ff332dc79bf in CPyCppyy::CPPFunction::Call (this=0x55de8f40b540, self=
0x7ff332488e10: 0x0, args=<optimized out>, nargsf=<optimized out>, kwds=<optimized out>, ctxt=0x7ffec545f130) at src/CPPFunction.cxx:89
#18 0x00007ff332dd1e40 in CPyCppyy::(anonymous namespace)::mp_vectorcall (pymeth=0x7ff332488e00, args=0x7ffec545f2e0, nargsf=2, kwds=0x0) at src/CPPOverload.cxx:637
#19 0x000055de857de979 in _PyObject_VectorcallTstate (kwnames=0x0, nargsf=2, args=0x7ffec545f2e0, callable=0x7ff332488e00, tstate=0x55de86b04250) at ./Include/cpython/abstract.h:118
#20 object_vacall (tstate=0x55de86b04250, base=base
entry=0x0, callable=callable
entry=0x7ff332488e00, vargs=vargs
entry=0x7ffec545f358) at Objects/call.c:792
#21 0x000055de857e0b6b in PyObject_CallFunctionObjArgs (callable=callable
entry=0x7ff332488e00) at Objects/call.c:899
#22 0x00007ff332dcae72 in CPyCppyy::op_str_internal (isBound=false, lshift=0x7ff332488e00, pyobj=0x7ff339b8b680) at src/CPPInstance.cxx:594
#23 CPyCppyy::op_str (self=0x7ff339b8b680) at src/CPPInstance.cxx:664
#24 0x000055de85819997 in PyObject_Str (v=0x7ff339b8b680) at Objects/object.c:479
#25 PyObject_Str (v=0x7ff339b8b680) at Objects/object.c:442
#26 0x000055de85873855 in unicode_new (type=0x55de85ad55c0 <PyUnicode_Type>, args=<optimized out>, kwds=<optimized out>) at Objects/unicodeobject.c:15414
#27 0x000055de85830ef5 in type_call (type=type
entry=0x55de85ad55c0 <PyUnicode_Type>, args=args
entry=0x7ff339cb24f0, kwds=kwds
entry=0x0) at Objects/typeobject.c:1014
#28 0x000055de857de490 in _PyObject_MakeTpCall (tstate=0x55de86b04250, callable=0x55de85ad55c0 <PyUnicode_Type>, args=<optimized out>, nargs=<optimized out>, keywords=0x0) at Objects/call.c:191
#29 0x000055de857cd9b4 in _PyObject_VectorcallTstate (kwnames=<optimized out>, nargsf=<optimized out>, args=<optimized out>, callable=<optimized out>, tstate=<optimized out>) at ./Include/cpython/abstract.h:116
#30 _PyObject_VectorcallTstate (kwnames=<optimized out>, nargsf=<optimized out>, args=<optimized out>, callable=<optimized out>, tstate=<optimized out>) at ./Include/cpython/abstract.h:103
#31 PyObject_Vectorcall (kwnames=<optimized out>, nargsf=<optimized out>, args=<optimized out>, callable=<optimized out>) at ./Include/cpython/abstract.h:127
#32 call_function (kwnames=0x0, oparg=<optimized out>, pp_stack=<synthetic pointer>, tstate=<optimized out>) at Python/ceval.c:5075
#33 _PyEval_EvalFrameDefault (tstate=<optimized out>, f=<optimized out>, throwflag=<optimized out>) at Python/ceval.c:3518
#34 0x000055de85890055 in _PyEval_EvalFrame (throwflag=0, f=0x7ff339b80400, tstate=0x55de86b04250) at ./Include/internal/pycore_ceval.h:40
#35 _PyEval_EvalCode (tstate=0x55de86b04250, _co=_co
entry=0x7ff332489500, globals=globals
entry=0x7ff339c51340, locals=locals
entry=0x7ff339c51340, args=args
entry=0x0, argcount=argcount
entry=0, kwnames=0x0, kwargs=0x0, kwcount=0, kwstep=2, defs=0x0, defcount=0, kwdefs=0x0, closure=0x0, name=0x0, qualname=0x0) at Python/ceval.c:4327
#36 0x000055de85890386 in _PyEval_EvalCodeWithName (qualname=0x0, name=0x0, closure=0x0, kwdefs=0x0, defcount=0, defs=0x0, kwstep=2, kwcount=0, kwargs=0x0, kwnames=0x0, argcount=0, args=0x0, locals=0x7ff339c51340, globals=0x7ff339c51340, _co=0x7ff332489500) at Python/ceval.c:4359
#37 PyEval_EvalCodeEx (closure=0x0, kwdefs=0x0, defcount=0, defs=0x0, kwcount=0, kws=0x0, argcount=0, args=0x0, locals=0x7ff339c51340, globals=0x7ff339c51340, _co=0x7ff332489500) at Python/ceval.c:4375
#38 PyEval_EvalCode (co=co
entry=0x7ff332489500, globals=globals
entry=0x7ff339c51340, locals=locals
entry=0x7ff339c51340) at Python/ceval.c:826
#39 0x000055de858cd937 in run_eval_code_obj (locals=0x7ff339c51340, globals=0x7ff339c51340, co=0x7ff332489500, tstate=0x55de86b04250) at Python/pythonrun.c:1219
#40 run_mod (mod=mod
entry=0x55de86c3aa08, filename=filename
entry=0x7ff339bdc9b0, globals=0x7ff339c51340, locals=0x7ff339c51340, flags=flags
entry=0x7ffec545fb28, arena=arena
entry=0x7ff339becbb0) at Python/pythonrun.c:1240
#41 0x000055de858cf0c0 in PyRun_InteractiveOneObjectEx (fp=fp
entry=0x7ff33a1c1a00 <_IO_2_1_stdin_>, filename=filename
entry=0x7ff339bdc9b0, flags=flags
entry=0x7ffec545fb28) at Python/pythonrun.c:273
#42 0x000055de858cf366 in PyRun_InteractiveLoopFlags (fp=fp
entry=0x7ff33a1c1a00 <_IO_2_1_stdin_>, filename_str=filename_str
entry=0x55de859d5132 "<stdin>", flags=flags
entry=0x7ffec545fb28) at Python/pythonrun.c:126
#43 0x000055de858cfcbe in PyRun_AnyFileExFlags (fp=0x7ff33a1c1a00 <_IO_2_1_stdin_>, filename=filename
entry=0x55de859d5132 "<stdin>", closeit=closeit
entry=0, flags=flags
entry=0x7ffec545fb28) at Python/pythonrun.c:85
#44 0x000055de857d1c59 in pymain_run_stdin (cf=0x7ffec545fb28, config=0x55de86b02b40) at Modules/main.c:512
#45 pymain_run_python (exitcode=exitcode
entry=0x7ffec545fc50) at Modules/main.c:601
#46 0x000055de857d2038 in Py_RunMain () at Modules/main.c:677
#47 pymain_main (args=0x7ffec545fc10) at Modules/main.c:707
#48 Py_BytesMain (argc=<optimized out>, argv=<optimized out>) at Modules/main.c:731
#49 0x00007ff33a02a09b in __libc_start_main (main=0x55de857c56d0 <main>, argc=1, argv=0x7ffec545fd58, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7ffec545fd48) at ../csu/libc-start.c:308
#50 0x000055de857d0cfa in _start () at ./Include/object.h:430
 *** Break *** segmentation violation
#0  0x00007ff33a0cc437 in __GI___waitpid (pid=13485, stat_loc=stat_loc
entry=0x7ffec545c5d8, options=options
entry=0) at ../sysdeps/unix/sysv/linux/waitpid.c:30
#1  0x00007ff33a04a5df in do_system (line=<optimized out>) at ../sysdeps/posix/system.c:149
#2  0x00007ff33982b355 in CppyyLegacy::TUnixSystem::StackTrace() () from /home/dillan/git_projects/svls/env_dbg/lib/python3.9/site-packages/cppyy_backend/lib/libCoreLegacy.so
#3  0x00007ff334f96b78 in (anonymous namespace)::do_trace (sig=1) at src/clingwrapper.cxx:199
#4  (anonymous namespace)::TExceptionHandlerImp::HandleException (this=<optimized out>, sig=1) at src/clingwrapper.cxx:218
#5  0x00007ff339829e61 in CppyyLegacy::TUnixSystem::DispatchSignals(CppyyLegacy::ESignals) () from /home/dillan/git_projects/svls/env_dbg/lib/python3.9/site-packages/cppyy_backend/lib/libCoreLegacy.so
#6  <signal handler called>
#7  __memmove_sse2_unaligned_erms () at ../sysdeps/x86_64/multiarch/memmove-vec-unaligned-erms.S:440
#8  0x00007ff339623998 in std::basic_streambuf<char, std::char_traits<char> >::xsputn(char const*, long) () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#9  0x00007ff339614b34 in std::basic_ostream<char, std::char_traits<char> >& std::__ostream_insert<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*, long) () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#10 0x00007ff332421023 in ?? ()
#11 0x00007ffec545f150 in ?? ()
#12 0x00007ff334f968de in WrapperCall (method=94414373789536, nargs=2, args_=0x7ffec545eee8, self=0x0, result=0x7ffec545eee8) at src/clingwrapper.cxx:848
#13 0x00007ff334f97413 in Cppyy::CallR (method=<optimized out>, self=<optimized out>, nargs=<optimized out>, args=<optimized out>) at src/clingwrapper.cxx:916
#14 0x00007ff332df71df in CPyCppyy::(anonymous namespace)::InstanceRefExecutor::Execute (this=0x55de8efc0710, method=<optimized out>, self=<optimized out>, ctxt=<optimized out>) at src/Executors.cxx:624
#15 0x00007ff332dccc79 in CPyCppyy::CPPMethod::ExecuteFast (ctxt=0x7ffec545f130, offset=0, self=0x0, this=0x55de8f40b540) at src/CPPMethod.cxx:853
#16 CPyCppyy::CPPMethod::Execute (this=this
entry=0x55de8f40b540, self=self
entry=0x0, offset=offset
entry=0, ctxt=ctxt
entry=0x7ffec545f130) at src/CPPMethod.cxx:853
#17 0x00007ff332dc79bf in CPyCppyy::CPPFunction::Call (this=0x55de8f40b540, self=
0x7ff332488e10: 0x0, args=<optimized out>, nargsf=<optimized out>, kwds=<optimized out>, ctxt=0x7ffec545f130) at src/CPPFunction.cxx:89
#18 0x00007ff332dd1e40 in CPyCppyy::(anonymous namespace)::mp_vectorcall (pymeth=0x7ff332488e00, args=0x7ffec545f2e0, nargsf=2, kwds=0x0) at src/CPPOverload.cxx:637
#19 0x000055de857de979 in _PyObject_VectorcallTstate (kwnames=0x0, nargsf=2, args=0x7ffec545f2e0, callable=0x7ff332488e00, tstate=0x55de86b04250) at ./Include/cpython/abstract.h:118
#20 object_vacall (tstate=0x55de86b04250, base=base
entry=0x0, callable=callable
entry=0x7ff332488e00, vargs=vargs
entry=0x7ffec545f358) at Objects/call.c:792
#21 0x000055de857e0b6b in PyObject_CallFunctionObjArgs (callable=callable
entry=0x7ff332488e00) at Objects/call.c:899
#22 0x00007ff332dcae72 in CPyCppyy::op_str_internal (isBound=false, lshift=0x7ff332488e00, pyobj=0x7ff339b8b680) at src/CPPInstance.cxx:594
#23 CPyCppyy::op_str (self=0x7ff339b8b680) at src/CPPInstance.cxx:664
#24 0x000055de85819997 in PyObject_Str (v=0x7ff339b8b680) at Objects/object.c:479
#25 PyObject_Str (v=0x7ff339b8b680) at Objects/object.c:442
#26 0x000055de85873855 in unicode_new (type=0x55de85ad55c0 <PyUnicode_Type>, args=<optimized out>, kwds=<optimized out>) at Objects/unicodeobject.c:15414
#27 0x000055de85830ef5 in type_call (type=type
entry=0x55de85ad55c0 <PyUnicode_Type>, args=args
entry=0x7ff339cb24f0, kwds=kwds
entry=0x0) at Objects/typeobject.c:1014
#28 0x000055de857de490 in _PyObject_MakeTpCall (tstate=0x55de86b04250, callable=0x55de85ad55c0 <PyUnicode_Type>, args=<optimized out>, nargs=<optimized out>, keywords=0x0) at Objects/call.c:191
#29 0x000055de857cd9b4 in _PyObject_VectorcallTstate (kwnames=<optimized out>, nargsf=<optimized out>, args=<optimized out>, callable=<optimized out>, tstate=<optimized out>) at ./Include/cpython/abstract.h:116
#30 _PyObject_VectorcallTstate (kwnames=<optimized out>, nargsf=<optimized out>, args=<optimized out>, callable=<optimized out>, tstate=<optimized out>) at ./Include/cpython/abstract.h:103
#31 PyObject_Vectorcall (kwnames=<optimized out>, nargsf=<optimized out>, args=<optimized out>, callable=<optimized out>) at ./Include/cpython/abstract.h:127
#32 call_function (kwnames=0x0, oparg=<optimized out>, pp_stack=<synthetic pointer>, tstate=<optimized out>) at Python/ceval.c:5075
#33 _PyEval_EvalFrameDefault (tstate=<optimized out>, f=<optimized out>, throwflag=<optimized out>) at Python/ceval.c:3518
#34 0x000055de85890055 in _PyEval_EvalFrame (throwflag=0, f=0x7ff339b80400, tstate=0x55de86b04250) at ./Include/internal/pycore_ceval.h:40
#35 _PyEval_EvalCode (tstate=0x55de86b04250, _co=_co
entry=0x7ff332489500, globals=globals
entry=0x7ff339c51340, locals=locals
entry=0x7ff339c51340, args=args
entry=0x0, argcount=argcount
entry=0, kwnames=0x0, kwargs=0x0, kwcount=0, kwstep=2, defs=0x0, defcount=0, kwdefs=0x0, closure=0x0, name=0x0, qualname=0x0) at Python/ceval.c:4327
#36 0x000055de85890386 in _PyEval_EvalCodeWithName (qualname=0x0, name=0x0, closure=0x0, kwdefs=0x0, defcount=0, defs=0x0, kwstep=2, kwcount=0, kwargs=0x0, kwnames=0x0, argcount=0, args=0x0, locals=0x7ff339c51340, globals=0x7ff339c51340, _co=0x7ff332489500) at Python/ceval.c:4359
#37 PyEval_EvalCodeEx (closure=0x0, kwdefs=0x0, defcount=0, defs=0x0, kwcount=0, kws=0x0, argcount=0, args=0x0, locals=0x7ff339c51340, globals=0x7ff339c51340, _co=0x7ff332489500) at Python/ceval.c:4375
#38 PyEval_EvalCode (co=co
entry=0x7ff332489500, globals=globals
entry=0x7ff339c51340, locals=locals
entry=0x7ff339c51340) at Python/ceval.c:826
#39 0x000055de858cd937 in run_eval_code_obj (locals=0x7ff339c51340, globals=0x7ff339c51340, co=0x7ff332489500, tstate=0x55de86b04250) at Python/pythonrun.c:1219
#40 run_mod (mod=mod
entry=0x55de86c3aa08, filename=filename
entry=0x7ff339bdc9b0, globals=0x7ff339c51340, locals=0x7ff339c51340, flags=flags
entry=0x7ffec545fb28, arena=arena
entry=0x7ff339becbb0) at Python/pythonrun.c:1240
#41 0x000055de858cf0c0 in PyRun_InteractiveOneObjectEx (fp=fp
entry=0x7ff33a1c1a00 <_IO_2_1_stdin_>, filename=filename
entry=0x7ff339bdc9b0, flags=flags
entry=0x7ffec545fb28) at Python/pythonrun.c:273
#42 0x000055de858cf366 in PyRun_InteractiveLoopFlags (fp=fp
entry=0x7ff33a1c1a00 <_IO_2_1_stdin_>, filename_str=filename_str
entry=0x55de859d5132 "<stdin>", flags=flags
entry=0x7ffec545fb28) at Python/pythonrun.c:126
#43 0x000055de858cfcbe in PyRun_AnyFileExFlags (fp=0x7ff33a1c1a00 <_IO_2_1_stdin_>, filename=filename
entry=0x55de859d5132 "<stdin>", closeit=closeit
entry=0, flags=flags
entry=0x7ffec545fb28) at Python/pythonrun.c:85
#44 0x000055de857d1c59 in pymain_run_stdin (cf=0x7ffec545fb28, config=0x55de86b02b40) at Modules/main.c:512
#45 pymain_run_python (exitcode=exitcode
entry=0x7ffec545fc50) at Modules/main.c:601
#46 0x000055de857d2038 in Py_RunMain () at Modules/main.c:677
#47 pymain_main (args=0x7ffec545fc10) at Modules/main.c:707
#48 Py_BytesMain (argc=<optimized out>, argv=<optimized out>) at Modules/main.c:731
#49 0x00007ff33a02a09b in __libc_start_main (main=0x55de857c56d0 <main>, argc=1, argv=0x7ffec545fd58, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7ffec545fd48) at ../csu/libc-start.c:308
#50 0x000055de857d0cfa in _start () at ./Include/object.h:430

@wlav
Copy link
Owner

wlav commented Sep 23, 2021

Neither seems to make sense: the access of a data member would be a pointer lookup, not a function call (as each of the tracebacks show). Is it not the str() part that is causing the crash? (str is actually a rather complicated beasty, calling/trying different conversions, so it would surprise me a whole lot less than an issue with a data member lookup).

@DillanCMills
Copy link
Author

Actually yes that is true. At the interactive prompt if I just type body.name it returns the pointer:

>>> instance.body.name
<cppyy.gbl.std.basic_string_view<char> object at 0x55621d8ef398>

But if I try to print it or convert it to a string or otherwise access the contents, that is where it crashes. I have used those conversions on other string_views without issue previously.

>>> instance.name
<cppyy.gbl.std.basic_string_view<char> object at 0x55621d8ef348>
>>> str(instance.name)
'foo'
'''

@wlav
Copy link
Owner

wlav commented Sep 23, 2021

Most likely cause is then that the string_view is pointing into some data that is no longer there.

Long chains of data member accesses should be okay, as cppyy places lifelines if the accessed member falls inside the instance its accessed in. Nevertheless, can you see whether this:

body = instance.body
print(str(body.name))

makes a difference?

I'm thinking that there is a temporary std::string returned somewhere that is then wrapped by the std::string_view. Since the life line check is on the address falling within the instance that holds it, the temporary std::string_view would not (the std::string` would). I'll see whether I can cook some reproducer (normally this would only happen with at least a function call somewhere).

@DillanCMills
Copy link
Author

print(str(body.name)) segfaulted, no difference. The thing I find most interesting is if I call this other function that is internal to the C++, a serializer that walks the tree and converts it to JSON, It prints it out just fine.

@DillanCMills
Copy link
Author

It might be an issue in the library. I tried creating the same code in C++ and I got a "terminate called without an active exception. Aborted" error at about the same point. I am talking with the library maintainer to get his thoughts on the issue.

@DillanCMills
Copy link
Author

DillanCMills commented Sep 24, 2021

Slightly unrelated, but possibly not - how does cppyy handle custom class iterators? The iterator object holds a pointer to the class object, so would I just need to cast to the original type to get the underlying type?

In C++, I am able to do

for (auto& member: elem.members()) { }

Where elem.members() returns an iterator:

    /// Gets an iterator to the members contained in the scope.
    iterator_range<iterator> members() const {
        return { firstMember, nullptr };
    }

But on the Python side, I don't think I can call for member in elem.members(), can I? I tried briefly but did not see results I was expecting. I have access to other operators like size and get_at_index type things, so I can in theory work around it, but each is still returning an iterator. I believe doing a __deref__ allows me to access the correct class in this case. Here is the iterator class header, for reference:

    class iterator : public iterator_facade<iterator, std::forward_iterator_tag, const Symbol> {
    public:
        iterator() : current(nullptr) {}
        iterator(const Symbol* firstSymbol) : current(firstSymbol) {}
        iterator(const iterator& other) : current(other.current) {}

        iterator& operator=(const iterator& other) {
            current = other.current;
            return *this;
        }

        bool operator==(const iterator& other) const { return current == other.current; }

        const Symbol& operator*() const { return *current; }
        const Symbol& operator*() { return *current; }

        iterator& operator++();

        iterator operator++(int) {
            iterator tmp = *this;
            ++(*this);
            return tmp;
        }

    private:
        const Symbol* current;
    };

@DillanCMills
Copy link
Author

DillanCMills commented Sep 24, 2021

One more segfault, for record keeping

segmentation fault
body.getParentScope().getCompilation().getAttributes(body)
 *** Break *** segmentation violation
#0  0x00007f2ff0415437 in __GI___waitpid (pid=4950, stat_loc=stat_loc
entry=0x7ffd113e4018, options=options
entry=0) at ../sysdeps/unix/sysv/linux/waitpid.c:30
#1  0x00007f2ff03935df in do_system (line=<optimized out>) at ../sysdeps/posix/system.c:149
#2  0x00007f2fefb74355 in CppyyLegacy::TUnixSystem::StackTrace() () from /home/dillan/git_projects/svls/env_dbg/lib/python3.9/site-packages/cppyy_backend/lib/libCoreLegacy.so
#3  0x00007f2feb2dfd08 in (anonymous namespace)::do_trace (sig=1) at src/clingwrapper.cxx:199
#4  (anonymous namespace)::TExceptionHandlerImp::HandleException (this=<optimized out>, sig=1) at src/clingwrapper.cxx:212
#5  0x00007f2fefb72e61 in CppyyLegacy::TUnixSystem::DispatchSignals(CppyyLegacy::ESignals) () from /home/dillan/git_projects/svls/env_dbg/lib/python3.9/site-packages/cppyy_backend/lib/libCoreLegacy.so
#6  <signal handler called>
#7  0x00007f2fe7d5ea7e in ska::fibonacci_hash_policy::index_for_hash (this=0x55f10000032e, hash=94495485481104) at /home/dillan/git_projects/svls/external/slang/source/../external/flat_hash_map.hpp:1274
#8  ska::detailv3::sherwood_v3_table<std::pair<void const*, nonstd::span_lite::span<slang::AttributeSymbol const* const, 18446744073709551615ul> >, void const*, std::hash<void const*>, ska::detailv3::KeyOrValueHasher<void const*, std::pair<void const*, nonstd::span_lite::span<slang::AttributeSymbol const* const, 18446744073709551615ul> >, std::hash<void const*> >, std::equal_to<void const*>, ska::detailv3::KeyOrValueEquality<void const*, std::pair<void const*, nonstd::span_lite::span<slang::AttributeSymbol const* const, 18446744073709551615ul> >, std::equal_to<void const*> >, std::allocator<std::pair<void const*, nonstd::span_lite::span<slang::AttributeSymbol const* const, 18446744073709551615ul> > >, std::allocator<ska::detailv3::sherwood_v3_entry<std::pair<void const*, nonstd::span_lite::span<slang::AttributeSymbol const* const, 18446744073709551615ul> > > > >::find (this=0x55f10000031e, key=<optimized out>) at /home/dillan/git_projects/svls/external/slang/source/../external/flat_hash_map.hpp:542
#9  ska::detailv3::sherwood_v3_table<std::pair<void const*, nonstd::span_lite::span<slang::AttributeSymbol const* const, 18446744073709551615ul> >, void const*, std::hash<void const*>, ska::detailv3::KeyOrValueHasher<void const*, std::pair<void const*, nonstd::span_lite::span<slang::AttributeSymbol const* const, 18446744073709551615ul> >, std::hash<void const*> >, std::equal_to<void const*>, ska::detailv3::KeyOrValueEquality<void const*, std::pair<void const*, nonstd::span_lite::span<slang::AttributeSymbol const* const, 18446744073709551615ul> >, std::equal_to<void const*> >, std::allocator<std::pair<void const*, nonstd::span_lite::span<slang::AttributeSymbol const* const, 18446744073709551615ul> > >, std::allocator<ska::detailv3::sherwood_v3_entry<std::pair<void const*, nonstd::span_lite::span<slang::AttributeSymbol const* const, 18446744073709551615ul> > > > >::find (this=0x55f10000031e, key=<optimized out>) at /home/dillan/git_projects/svls/external/slang/source/../external/flat_hash_map.hpp:553
#10 slang::Compilation::getAttributes (this=0x55f100000006, ptr=<optimized out>) at /home/dillan/git_projects/svls/external/slang/source/compilation/Compilation.cpp:617
#11 slang::Compilation::getAttributes (this=0x55f100000006, symbol=...) at /home/dillan/git_projects/svls/external/slang/source/compilation/Compilation.cpp:605
#12 0x00007f2fe8726013 in ?? ()
#13 0x00007ffd113e6b50 in ?? ()
#14 0x00007f2feb2df8de in WrapperCall (method=94495474788608, nargs=1, args_=0x55f17234d8d0, self=0x55f100000006, result=0x55f17234d8d0) at src/clingwrapper.cxx:848
#15 0x00007f2feb2e0646 in Cppyy::CallO (method=method
entry=94495474788608, self=self
entry=0x55f100000006, nargs=1, args=0x7ffd113e6b50, result_type=result_type
entry=93) at src/clingwrapper.cxx:957
#16 0x00007f2fe9142110 in GILCallO (klass=93, ctxt=0x7ffd113e6b30, self=0x55f100000006, method=94495474788608) at src/CallContext.h:100
#17 GILCallO (klass=93, ctxt=0x7ffd113e6b30, self=0x55f100000006, method=94495474788608) at src/Executors.cxx:80
#18 CPyCppyy::(anonymous namespace)::InstanceExecutor::Execute (this=0x55f171fcaff0, method=94495474788608, self=0x55f100000006, ctxt=0x7ffd113e6b30) at src/Executors.cxx:592
#19 0x00007f2fe9115c79 in CPyCppyy::CPPMethod::ExecuteFast (ctxt=<optimized out>, offset=<optimized out>, self=<optimized out>, this=0x55f171352b10) at src/CPPMethod.cxx:853
#20 CPyCppyy::CPPMethod::Execute (this=0x55f171352b10, self=<optimized out>, offset=<optimized out>, ctxt=<optimized out>) at src/CPPMethod.cxx:853
#21 0x00007f2fe9115f96 in CPyCppyy::CPPMethod::Call (this=0x55f171352b10, self=
0x7f2fe890cc50: 0x7f2fe87d45c0, args=<optimized out>, nargsf=<optimized out>, kwds=<optimized out>, ctxt=0x7ffd113e6b30) at src/CPPMethod.cxx:913
#22 0x00007f2fe911a5c0 in CPyCppyy::(anonymous namespace)::mp_vectorcall (pymeth=0x7f2fe890cc40, args=0x7f2fe8906690, nargsf=9223372036854775810, kwds=0x0) at src/CPPOverload.cxx:708
#23 0x000055f1683ab141 in _PyObject_VectorcallTstate (kwnames=0x0, nargsf=<optimized out>, args=0x7f2fe8906690, callable=0x7f2fe890cc40, tstate=0x55f1699a3250) at ./Include/cpython/abstract.h:118
#24 PyObject_Vectorcall (kwnames=0x0, nargsf=<optimized out>, args=0x7f2fe8906690, callable=0x7f2fe890cc40) at ./Include/cpython/abstract.h:127
#25 call_function (kwnames=0x0, oparg=<optimized out>, pp_stack=<synthetic pointer>, tstate=<optimized out>) at Python/ceval.c:5075
#26 _PyEval_EvalFrameDefault (tstate=<optimized out>, f=<optimized out>, throwflag=<optimized out>) at Python/ceval.c:3504
#27 0x000055f168471055 in _PyEval_EvalFrame (throwflag=0, f=0x7f2fe8906520, tstate=0x55f1699a3250) at ./Include/internal/pycore_ceval.h:40
#28 _PyEval_EvalCode (tstate=0x55f1699a3250, _co=_co
entry=0x7f2fe87d2d40, globals=globals
entry=0x7f2feff9a340, locals=locals
entry=0x7f2feff9a340, args=args
entry=0x0, argcount=argcount
entry=0, kwnames=0x0, kwargs=0x0, kwcount=0, kwstep=2, defs=0x0, defcount=0, kwdefs=0x0, closure=0x0, name=0x0, qualname=0x0) at Python/ceval.c:4327
#29 0x000055f168471386 in _PyEval_EvalCodeWithName (qualname=0x0, name=0x0, closure=0x0, kwdefs=0x0, defcount=0, defs=0x0, kwstep=2, kwcount=0, kwargs=0x0, kwnames=0x0, argcount=0, args=0x0, locals=0x7f2feff9a340, globals=0x7f2feff9a340, _co=0x7f2fe87d2d40) at Python/ceval.c:4359
#30 PyEval_EvalCodeEx (closure=0x0, kwdefs=0x0, defcount=0, defs=0x0, kwcount=0, kws=0x0, argcount=0, args=0x0, locals=0x7f2feff9a340, globals=0x7f2feff9a340, _co=0x7f2fe87d2d40) at Python/ceval.c:4375
#31 PyEval_EvalCode (co=co
entry=0x7f2fe87d2d40, globals=globals
entry=0x7f2feff9a340, locals=locals
entry=0x7f2feff9a340) at Python/ceval.c:826
#32 0x000055f1684ae937 in run_eval_code_obj (locals=0x7f2feff9a340, globals=0x7f2feff9a340, co=0x7f2fe87d2d40, tstate=0x55f1699a3250) at Python/pythonrun.c:1219
#33 run_mod (mod=mod
entry=0x55f169ad9e08, filename=filename
entry=0x7f2feff259f0, globals=0x7f2feff9a340, locals=0x7f2feff9a340, flags=flags
entry=0x7ffd113e7038, arena=arena
entry=0x7f2feff35bb0) at Python/pythonrun.c:1240
#34 0x000055f1684b00c0 in PyRun_InteractiveOneObjectEx (fp=fp
entry=0x7f2ff050aa00 <_IO_2_1_stdin_>, filename=filename
entry=0x7f2feff259f0, flags=flags
entry=0x7ffd113e7038) at Python/pythonrun.c:273
#35 0x000055f1684b0366 in PyRun_InteractiveLoopFlags (fp=fp
entry=0x7f2ff050aa00 <_IO_2_1_stdin_>, filename_str=filename_str
entry=0x55f1685b6132 "<stdin>", flags=flags
entry=0x7ffd113e7038) at Python/pythonrun.c:126
#36 0x000055f1684b0cbe in PyRun_AnyFileExFlags (fp=0x7f2ff050aa00 <_IO_2_1_stdin_>, filename=filename
entry=0x55f1685b6132 "<stdin>", closeit=closeit
entry=0, flags=flags
entry=0x7ffd113e7038) at Python/pythonrun.c:85
#37 0x000055f1683b2c59 in pymain_run_stdin (cf=0x7ffd113e7038, config=0x55f1699a1b40) at Modules/main.c:512
#38 pymain_run_python (exitcode=exitcode
entry=0x7ffd113e7160) at Modules/main.c:601
#39 0x000055f1683b3038 in Py_RunMain () at Modules/main.c:677
#40 pymain_main (args=0x7ffd113e7120) at Modules/main.c:707
#41 Py_BytesMain (argc=<optimized out>, argv=<optimized out>) at Modules/main.c:731
#42 0x00007f2ff037309b in __libc_start_main (main=0x55f1683a66d0 <main>, argc=1, argv=0x7ffd113e7268, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7ffd113e7258) at ../csu/libc-start.c:308
#43 0x000055f1683b1cfa in _start () at Python/ceval.c:5185
 *** Break *** segmentation violation
#0  0x00007f2ff0415437 in __GI___waitpid (pid=5205, stat_loc=stat_loc
entry=0x7ffd113e4018, options=options
entry=0) at ../sysdeps/unix/sysv/linux/waitpid.c:30
#1  0x00007f2ff03935df in do_system (line=<optimized out>) at ../sysdeps/posix/system.c:149
#2  0x00007f2fefb74355 in CppyyLegacy::TUnixSystem::StackTrace() () from /home/dillan/git_projects/svls/env_dbg/lib/python3.9/site-packages/cppyy_backend/lib/libCoreLegacy.so
#3  0x00007f2feb2dfb78 in (anonymous namespace)::do_trace (sig=1) at src/clingwrapper.cxx:199
#4  (anonymous namespace)::TExceptionHandlerImp::HandleException (this=<optimized out>, sig=1) at src/clingwrapper.cxx:218
#5  0x00007f2fefb72e61 in CppyyLegacy::TUnixSystem::DispatchSignals(CppyyLegacy::ESignals) () from /home/dillan/git_projects/svls/env_dbg/lib/python3.9/site-packages/cppyy_backend/lib/libCoreLegacy.so
#6  <signal handler called>
#7  0x00007f2fe7d5ea7e in ska::fibonacci_hash_policy::index_for_hash (this=0x55f10000032e, hash=94495485481104) at /home/dillan/git_projects/svls/external/slang/source/../external/flat_hash_map.hpp:1274
#8  ska::detailv3::sherwood_v3_table<std::pair<void const*, nonstd::span_lite::span<slang::AttributeSymbol const* const, 18446744073709551615ul> >, void const*, std::hash<void const*>, ska::detailv3::KeyOrValueHasher<void const*, std::pair<void const*, nonstd::span_lite::span<slang::AttributeSymbol const* const, 18446744073709551615ul> >, std::hash<void const*> >, std::equal_to<void const*>, ska::detailv3::KeyOrValueEquality<void const*, std::pair<void const*, nonstd::span_lite::span<slang::AttributeSymbol const* const, 18446744073709551615ul> >, std::equal_to<void const*> >, std::allocator<std::pair<void const*, nonstd::span_lite::span<slang::AttributeSymbol const* const, 18446744073709551615ul> > >, std::allocator<ska::detailv3::sherwood_v3_entry<std::pair<void const*, nonstd::span_lite::span<slang::AttributeSymbol const* const, 18446744073709551615ul> > > > >::find (this=0x55f10000031e, key=<optimized out>) at /home/dillan/git_projects/svls/external/slang/source/../external/flat_hash_map.hpp:542
#9  ska::detailv3::sherwood_v3_table<std::pair<void const*, nonstd::span_lite::span<slang::AttributeSymbol const* const, 18446744073709551615ul> >, void const*, std::hash<void const*>, ska::detailv3::KeyOrValueHasher<void const*, std::pair<void const*, nonstd::span_lite::span<slang::AttributeSymbol const* const, 18446744073709551615ul> >, std::hash<void const*> >, std::equal_to<void const*>, ska::detailv3::KeyOrValueEquality<void const*, std::pair<void const*, nonstd::span_lite::span<slang::AttributeSymbol const* const, 18446744073709551615ul> >, std::equal_to<void const*> >, std::allocator<std::pair<void const*, nonstd::span_lite::span<slang::AttributeSymbol const* const, 18446744073709551615ul> > >, std::allocator<ska::detailv3::sherwood_v3_entry<std::pair<void const*, nonstd::span_lite::span<slang::AttributeSymbol const* const, 18446744073709551615ul> > > > >::find (this=0x55f10000031e, key=<optimized out>) at /home/dillan/git_projects/svls/external/slang/source/../external/flat_hash_map.hpp:553
#10 slang::Compilation::getAttributes (this=0x55f100000006, ptr=<optimized out>) at /home/dillan/git_projects/svls/external/slang/source/compilation/Compilation.cpp:617
#11 slang::Compilation::getAttributes (this=0x55f100000006, symbol=...) at /home/dillan/git_projects/svls/external/slang/source/compilation/Compilation.cpp:605
#12 0x00007f2fe8726013 in ?? ()
#13 0x00007ffd113e6b50 in ?? ()
#14 0x00007f2feb2df8de in WrapperCall (method=94495474788608, nargs=1, args_=0x55f17234d8d0, self=0x55f100000006, result=0x55f17234d8d0) at src/clingwrapper.cxx:848
#15 0x00007f2feb2e0646 in Cppyy::CallO (method=method
entry=94495474788608, self=self
entry=0x55f100000006, nargs=1, args=0x7ffd113e6b50, result_type=result_type
entry=93) at src/clingwrapper.cxx:957
#16 0x00007f2fe9142110 in GILCallO (klass=93, ctxt=0x7ffd113e6b30, self=0x55f100000006, method=94495474788608) at src/CallContext.h:100
#17 GILCallO (klass=93, ctxt=0x7ffd113e6b30, self=0x55f100000006, method=94495474788608) at src/Executors.cxx:80
#18 CPyCppyy::(anonymous namespace)::InstanceExecutor::Execute (this=0x55f171fcaff0, method=94495474788608, self=0x55f100000006, ctxt=0x7ffd113e6b30) at src/Executors.cxx:592
#19 0x00007f2fe9115c79 in CPyCppyy::CPPMethod::ExecuteFast (ctxt=<optimized out>, offset=<optimized out>, self=<optimized out>, this=0x55f171352b10) at src/CPPMethod.cxx:853
#20 CPyCppyy::CPPMethod::Execute (this=0x55f171352b10, self=<optimized out>, offset=<optimized out>, ctxt=<optimized out>) at src/CPPMethod.cxx:853
#21 0x00007f2fe9115f96 in CPyCppyy::CPPMethod::Call (this=0x55f171352b10, self=
0x7f2fe890cc50: 0x7f2fe87d45c0, args=<optimized out>, nargsf=<optimized out>, kwds=<optimized out>, ctxt=0x7ffd113e6b30) at src/CPPMethod.cxx:913
#22 0x00007f2fe911a5c0 in CPyCppyy::(anonymous namespace)::mp_vectorcall (pymeth=0x7f2fe890cc40, args=0x7f2fe8906690, nargsf=9223372036854775810, kwds=0x0) at src/CPPOverload.cxx:708
#23 0x000055f1683ab141 in _PyObject_VectorcallTstate (kwnames=0x0, nargsf=<optimized out>, args=0x7f2fe8906690, callable=0x7f2fe890cc40, tstate=0x55f1699a3250) at ./Include/cpython/abstract.h:118
#24 PyObject_Vectorcall (kwnames=0x0, nargsf=<optimized out>, args=0x7f2fe8906690, callable=0x7f2fe890cc40) at ./Include/cpython/abstract.h:127
#25 call_function (kwnames=0x0, oparg=<optimized out>, pp_stack=<synthetic pointer>, tstate=<optimized out>) at Python/ceval.c:5075
#26 _PyEval_EvalFrameDefault (tstate=<optimized out>, f=<optimized out>, throwflag=<optimized out>) at Python/ceval.c:3504
#27 0x000055f168471055 in _PyEval_EvalFrame (throwflag=0, f=0x7f2fe8906520, tstate=0x55f1699a3250) at ./Include/internal/pycore_ceval.h:40
#28 _PyEval_EvalCode (tstate=0x55f1699a3250, _co=_co
entry=0x7f2fe87d2d40, globals=globals
entry=0x7f2feff9a340, locals=locals
entry=0x7f2feff9a340, args=args
entry=0x0, argcount=argcount
entry=0, kwnames=0x0, kwargs=0x0, kwcount=0, kwstep=2, defs=0x0, defcount=0, kwdefs=0x0, closure=0x0, name=0x0, qualname=0x0) at Python/ceval.c:4327
#29 0x000055f168471386 in _PyEval_EvalCodeWithName (qualname=0x0, name=0x0, closure=0x0, kwdefs=0x0, defcount=0, defs=0x0, kwstep=2, kwcount=0, kwargs=0x0, kwnames=0x0, argcount=0, args=0x0, locals=0x7f2feff9a340, globals=0x7f2feff9a340, _co=0x7f2fe87d2d40) at Python/ceval.c:4359
#30 PyEval_EvalCodeEx (closure=0x0, kwdefs=0x0, defcount=0, defs=0x0, kwcount=0, kws=0x0, argcount=0, args=0x0, locals=0x7f2feff9a340, globals=0x7f2feff9a340, _co=0x7f2fe87d2d40) at Python/ceval.c:4375
#31 PyEval_EvalCode (co=co
entry=0x7f2fe87d2d40, globals=globals
entry=0x7f2feff9a340, locals=locals
entry=0x7f2feff9a340) at Python/ceval.c:826
#32 0x000055f1684ae937 in run_eval_code_obj (locals=0x7f2feff9a340, globals=0x7f2feff9a340, co=0x7f2fe87d2d40, tstate=0x55f1699a3250) at Python/pythonrun.c:1219
#33 run_mod (mod=mod
entry=0x55f169ad9e08, filename=filename
entry=0x7f2feff259f0, globals=0x7f2feff9a340, locals=0x7f2feff9a340, flags=flags
entry=0x7ffd113e7038, arena=arena
entry=0x7f2feff35bb0) at Python/pythonrun.c:1240
#34 0x000055f1684b00c0 in PyRun_InteractiveOneObjectEx (fp=fp
entry=0x7f2ff050aa00 <_IO_2_1_stdin_>, filename=filename
entry=0x7f2feff259f0, flags=flags
entry=0x7ffd113e7038) at Python/pythonrun.c:273
#35 0x000055f1684b0366 in PyRun_InteractiveLoopFlags (fp=fp
entry=0x7f2ff050aa00 <_IO_2_1_stdin_>, filename_str=filename_str
entry=0x55f1685b6132 "<stdin>", flags=flags
entry=0x7ffd113e7038) at Python/pythonrun.c:126
#36 0x000055f1684b0cbe in PyRun_AnyFileExFlags (fp=0x7f2ff050aa00 <_IO_2_1_stdin_>, filename=filename
entry=0x55f1685b6132 "<stdin>", closeit=closeit
entry=0, flags=flags
entry=0x7ffd113e7038) at Python/pythonrun.c:85
#37 0x000055f1683b2c59 in pymain_run_stdin (cf=0x7ffd113e7038, config=0x55f1699a1b40) at Modules/main.c:512
#38 pymain_run_python (exitcode=exitcode
entry=0x7ffd113e7160) at Modules/main.c:601
#39 0x000055f1683b3038 in Py_RunMain () at Modules/main.c:677
#40 pymain_main (args=0x7ffd113e7120) at Modules/main.c:707
#41 Py_BytesMain (argc=<optimized out>, argv=<optimized out>) at Modules/main.c:731
#42 0x00007f2ff037309b in __libc_start_main (main=0x55f1683a66d0 <main>, argc=1, argv=0x7ffd113e7268, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7ffd113e7258) at ../csu/libc-start.c:308
#43 0x000055f1683b1cfa in _start () at Python/ceval.c:5185

@DillanCMills
Copy link
Author

DillanCMills commented Sep 24, 2021

According to the cppyy docs, this should work, right?:

>>> import cppyy.ll
>>> cppyy.set_debug()
>>> cppyy.ll.static_cast['const void*'](body)
input_line_105:7:41: error: cannot cast from type 'slang::InstanceBodySymbol' to pointer type 'const void *'
    T cppyy_static_cast(U val) { return static_cast<T>(val); }
                                        ^~~~~~~~~~~~~~~~~~~
note: in instantiation of function template specialization '__cppyy_internal::cppyy_static_cast<const void *, slang::InstanceBodySymbol>' requested here
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: Could not find "cppyy_static_cast<const void*>" (set cppyy.set_debug() for C++ errors):
  Failed to instantiate "cppyy_static_cast<const void*>(slang::InstanceBodySymbol&)"

I am trying to walk further into the library and see if I can figure out the exact line that is failing.

@wlav
Copy link
Owner

wlav commented Sep 24, 2021

For the iterator to work, the code is expecting begin() and end() methods on the container (and a way of dereferencing the iterator, but that's clearly there in the operator* in that definition above). A size() and operator[] for indexing should work as well, but get_at_index() is not recognized.

That cast fails b/c you can't cast a reference (default choice for object argument in templates if no other information is available) to a void*. Try:

cppyy.ll.static_cast['const void*', type(body).__cpp_name__+'*'](body)

But I think what you really want is simply:

cppyy.addressof(body)

@DillanCMills
Copy link
Author

DillanCMills commented Sep 24, 2021

comp.getRoot().members() includes begin, end, and size, so I assume that is sufficient. Here is what I see though:

>>> comp.getRoot().members()
<cppyy.gbl.slang.iterator_range<slang::Scope::iterator> object at 0x55e973ff8540>
>>> comp.getRoot().members()[0]
<cppyy.gbl.slang.Scope.iterator object at 0x55e9747f2f40>
>>> comp.getRoot().members()[1]
<cppyy.gbl.slang.Scope.iterator object at 0x55e9744242f0>
>>> comp.getRoot().members()[2]
<cppyy.gbl.slang.Scope.iterator object at 0x55e9746812d0>
>>> comp.getRoot().members().size()
2
>>> for x in comp.getRoot().members():
...     print(x)
... 
>>> 
>>> comp.getRoot().members().begin()
<cppyy.gbl.slang.Scope.iterator object at 0x55e9747e8f20>
>>> comp.getRoot().members().end()
<cppyy.gbl.slang.Scope.iterator object at 0x55e97436a1c0>

Thanks for the cast instructions, they worked, although in the end I think I was actually able to pass the object directly and it handled the conversion, the function just didn't return anything usable.

@DillanCMills
Copy link
Author

Okay, I had a bug in my C++ version but after getting that resolved, it is working fine on that side, so there is something wrong in the conversion to Python I think. Here are a couple snippets for comparison:

   auto& root = comp.getRoot();
   auto& elem = root.members()[1]->as<InstanceSymbol>();
   auto& body = elem.body;

   std::cout << body.name << '\n';  // outputs 'foo'
root = comp.getRoot()
elem = bind_object(root.members()[1].__deref__(), InstanceSymbol)
body = elem.body

print(body.name)  # segmentation fault

Both of these are created with parallel setup code preceding these lines, and up to accessing the properties of body, everything appears to be the same.

segmentation fault
 *** Break *** segmentation violation
#0  0x00007fd9f3325437 in __GI___waitpid (pid=14808, stat_loc=stat_loc
entry=0x7fffa9e5b4d8, options=options
entry=0) at ../sysdeps/unix/sysv/linux/waitpid.c:30
#1  0x00007fd9f32a35df in do_system (line=<optimized out>) at ../sysdeps/posix/system.c:149
#2  0x00007fd9f2a84355 in CppyyLegacy::TUnixSystem::StackTrace() () from /home/dillan/git_projects/svls/env_dbg/lib/python3.9/site-packages/cppyy_backend/lib/libCoreLegacy.so
#3  0x00007fd9ee1efd08 in (anonymous namespace)::do_trace (sig=1) at src/clingwrapper.cxx:199
#4  (anonymous namespace)::TExceptionHandlerImp::HandleException (this=<optimized out>, sig=1) at src/clingwrapper.cxx:212
#5  0x00007fd9f2a82e61 in CppyyLegacy::TUnixSystem::DispatchSignals(CppyyLegacy::ESignals) () from /home/dillan/git_projects/svls/env_dbg/lib/python3.9/site-packages/cppyy_backend/lib/libCoreLegacy.so
#6  <signal handler called>
#7  __memmove_sse2_unaligned_erms () at ../sysdeps/x86_64/multiarch/memmove-vec-unaligned-erms.S:440
#8  0x00007fd9f287c998 in std::basic_streambuf<char, std::char_traits<char> >::xsputn(char const*, long) () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#9  0x00007fd9f286db34 in std::basic_ostream<char, std::char_traits<char> >& std::__ostream_insert<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*, long) () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#10 0x00007fd9eb67a023 in ?? ()
#11 0x00007fffa9e5e060 in ?? ()
#12 0x00007fd9ee1ef8de in WrapperCall (method=94600561999904, nargs=2, args_=0x7fffa9e5ddf8, self=0x0, result=0x7fffa9e5ddf8) at src/clingwrapper.cxx:848
#13 0x00007fd9ee1f0413 in Cppyy::CallR (method=<optimized out>, self=<optimized out>, nargs=<optimized out>, args=<optimized out>) at src/clingwrapper.cxx:916
#14 0x00007fd9ec0501df in CPyCppyy::(anonymous namespace)::InstanceRefExecutor::Execute (this=0x5609e7efcd50, method=<optimized out>, self=<optimized out>, ctxt=<optimized out>) at src/Executors.cxx:624
#15 0x00007fd9ec025c79 in CPyCppyy::CPPMethod::ExecuteFast (ctxt=0x7fffa9e5e040, offset=0, self=0x0, this=0x5609e8b509d0) at src/CPPMethod.cxx:853
#16 CPyCppyy::CPPMethod::Execute (this=this
entry=0x5609e8b509d0, self=self
entry=0x0, offset=offset
entry=0, ctxt=ctxt
entry=0x7fffa9e5e040) at src/CPPMethod.cxx:853
#17 0x00007fd9ec0209bf in CPyCppyy::CPPFunction::Call (this=0x5609e8b509d0, self=
0x7fd9eb61aa90: 0x0, args=<optimized out>, nargsf=<optimized out>, kwds=<optimized out>, ctxt=0x7fffa9e5e040) at src/CPPFunction.cxx:89
#18 0x00007fd9ec02ae40 in CPyCppyy::(anonymous namespace)::mp_vectorcall (pymeth=0x7fd9eb61aa80, args=0x7fffa9e5e1f0, nargsf=2, kwds=0x0) at src/CPPOverload.cxx:637
#19 0x00005609dff6b979 in _PyObject_VectorcallTstate (kwnames=0x0, nargsf=2, args=0x7fffa9e5e1f0, callable=0x7fd9eb61aa80, tstate=0x5609e04e9250) at ./Include/cpython/abstract.h:118
#20 object_vacall (tstate=0x5609e04e9250, base=base
entry=0x0, callable=callable
entry=0x7fd9eb61aa80, vargs=vargs
entry=0x7fffa9e5e268) at Objects/call.c:792
#21 0x00005609dff6db6b in PyObject_CallFunctionObjArgs (callable=callable
entry=0x7fd9eb61aa80) at Objects/call.c:899
#22 0x00007fd9ec023e72 in CPyCppyy::op_str_internal (isBound=false, lshift=0x7fd9eb61aa80, pyobj=0x7fd9eb61b300) at src/CPPInstance.cxx:594
#23 CPyCppyy::op_str (self=0x7fd9eb61b300) at src/CPPInstance.cxx:664
#24 0x00005609dffa6997 in PyObject_Str (v=0x7fd9eb61b300) at Objects/object.c:479
#25 PyObject_Str (v=0x7fd9eb61b300) at Objects/object.c:442
#26 0x00005609e0104965 in PyFile_WriteObject (v=0x7fd9eb61b300, f=<optimized out>, flags=flags
entry=1) at Objects/fileobject.c:132
#27 0x00005609e013cc27 in builtin_print (self=<optimized out>, args=0x7fd9f2e3e980, nargs=1, kwnames=<optimized out>) at Python/bltinmodule.c:1874
#28 0x00005609e010ac0a in cfunction_vectorcall_FASTCALL_KEYWORDS (func=0x7fd9f2f07400, args=0x7fd9f2e3e980, nargsf=<optimized out>, kwnames=<optimized out>) at Objects/methodobject.c:446
#29 0x00005609dff58415 in _PyObject_VectorcallTstate (kwnames=0x0, nargsf=<optimized out>, args=0x7fd9f2e3e980, callable=0x7fd9f2f07400, tstate=0x5609e04e9250) at ./Include/cpython/abstract.h:118
#30 PyObject_Vectorcall (kwnames=0x0, nargsf=<optimized out>, args=0x7fd9f2e3e980, callable=0x7fd9f2f07400) at ./Include/cpython/abstract.h:127
#31 call_function (kwnames=0x0, oparg=<optimized out>, pp_stack=<synthetic pointer>, tstate=<optimized out>) at Python/ceval.c:5075
#32 _PyEval_EvalFrameDefault (tstate=<optimized out>, f=<optimized out>, throwflag=<optimized out>) at Python/ceval.c:3518
#33 0x00005609e001d055 in _PyEval_EvalFrame (throwflag=0, f=0x7fd9f2e3e810, tstate=0x5609e04e9250) at ./Include/internal/pycore_ceval.h:40
#34 _PyEval_EvalCode (tstate=0x5609e04e9250, _co=_co
entry=0x7fd9f2eb0870, globals=globals
entry=0x7fd9f2eaa340, locals=locals
entry=0x7fd9f2eaa340, args=args
entry=0x0, argcount=argcount
entry=0, kwnames=0x0, kwargs=0x0, kwcount=0, kwstep=2, defs=0x0, defcount=0, kwdefs=0x0, closure=0x0, name=0x0, qualname=0x0) at Python/ceval.c:4327
#35 0x00005609e001d386 in _PyEval_EvalCodeWithName (qualname=0x0, name=0x0, closure=0x0, kwdefs=0x0, defcount=0, defs=0x0, kwstep=2, kwcount=0, kwargs=0x0, kwnames=0x0, argcount=0, args=0x0, locals=0x7fd9f2eaa340, globals=0x7fd9f2eaa340, _co=0x7fd9f2eb0870) at Python/ceval.c:4359
#36 PyEval_EvalCodeEx (closure=0x0, kwdefs=0x0, defcount=0, defs=0x0, kwcount=0, kws=0x0, argcount=0, args=0x0, locals=0x7fd9f2eaa340, globals=0x7fd9f2eaa340, _co=0x7fd9f2eb0870) at Python/ceval.c:4375
#37 PyEval_EvalCode (co=co
entry=0x7fd9f2eb0870, globals=globals
entry=0x7fd9f2eaa340, locals=locals
entry=0x7fd9f2eaa340) at Python/ceval.c:826
#38 0x00005609e005a937 in run_eval_code_obj (locals=0x7fd9f2eaa340, globals=0x7fd9f2eaa340, co=0x7fd9f2eb0870, tstate=0x5609e04e9250) at Python/pythonrun.c:1219
#39 run_mod (mod=mod
entry=0x5609e95dddc8, filename=filename
entry=0x7fd9f2e35af0, globals=0x7fd9f2eaa340, locals=0x7fd9f2eaa340, flags=flags
entry=0x7fffa9e5ea08, arena=arena
entry=0x7fd9f2e45bb0) at Python/pythonrun.c:1240
#40 0x00005609e005c0c0 in PyRun_InteractiveOneObjectEx (fp=fp
entry=0x7fd9f341aa00 <_IO_2_1_stdin_>, filename=filename
entry=0x7fd9f2e35af0, flags=flags
entry=0x7fffa9e5ea08) at Python/pythonrun.c:273
#41 0x00005609e005c366 in PyRun_InteractiveLoopFlags (fp=fp
entry=0x7fd9f341aa00 <_IO_2_1_stdin_>, filename_str=filename_str
entry=0x5609e0162132 "<stdin>", flags=flags
entry=0x7fffa9e5ea08) at Python/pythonrun.c:126
#42 0x00005609e005ccbe in PyRun_AnyFileExFlags (fp=0x7fd9f341aa00 <_IO_2_1_stdin_>, filename=filename
entry=0x5609e0162132 "<stdin>", closeit=closeit
entry=0, flags=flags
entry=0x7fffa9e5ea08) at Python/pythonrun.c:85
#43 0x00005609dff5ec59 in pymain_run_stdin (cf=0x7fffa9e5ea08, config=0x5609e04e7b40) at Modules/main.c:512
#44 pymain_run_python (exitcode=exitcode
entry=0x7fffa9e5eb30) at Modules/main.c:601
#45 0x00005609dff5f038 in Py_RunMain () at Modules/main.c:677
#46 pymain_main (args=0x7fffa9e5eaf0) at Modules/main.c:707
#47 Py_BytesMain (argc=<optimized out>, argv=<optimized out>) at Modules/main.c:731
#48 0x00007fd9f328309b in __libc_start_main (main=0x5609dff526d0 <main>, argc=1, argv=0x7fffa9e5ec38, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7fffa9e5ec28) at ../csu/libc-start.c:308
#49 0x00005609dff5dcfa in _start () at ./Include/object.h:430
 *** Break *** segmentation violation
#0  0x00007fd9f3325437 in __GI___waitpid (pid=15121, stat_loc=stat_loc
entry=0x7fffa9e5b4d8, options=options
entry=0) at ../sysdeps/unix/sysv/linux/waitpid.c:30
#1  0x00007fd9f32a35df in do_system (line=<optimized out>) at ../sysdeps/posix/system.c:149
#2  0x00007fd9f2a84355 in CppyyLegacy::TUnixSystem::StackTrace() () from /home/dillan/git_projects/svls/env_dbg/lib/python3.9/site-packages/cppyy_backend/lib/libCoreLegacy.so
#3  0x00007fd9ee1efb78 in (anonymous namespace)::do_trace (sig=1) at src/clingwrapper.cxx:199
#4  (anonymous namespace)::TExceptionHandlerImp::HandleException (this=<optimized out>, sig=1) at src/clingwrapper.cxx:218
#5  0x00007fd9f2a82e61 in CppyyLegacy::TUnixSystem::DispatchSignals(CppyyLegacy::ESignals) () from /home/dillan/git_projects/svls/env_dbg/lib/python3.9/site-packages/cppyy_backend/lib/libCoreLegacy.so
#6  <signal handler called>
#7  __memmove_sse2_unaligned_erms () at ../sysdeps/x86_64/multiarch/memmove-vec-unaligned-erms.S:440
#8  0x00007fd9f287c998 in std::basic_streambuf<char, std::char_traits<char> >::xsputn(char const*, long) () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#9  0x00007fd9f286db34 in std::basic_ostream<char, std::char_traits<char> >& std::__ostream_insert<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*, long) () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#10 0x00007fd9eb67a023 in ?? ()
#11 0x00007fffa9e5e060 in ?? ()
#12 0x00007fd9ee1ef8de in WrapperCall (method=94600561999904, nargs=2, args_=0x7fffa9e5ddf8, self=0x0, result=0x7fffa9e5ddf8) at src/clingwrapper.cxx:848
#13 0x00007fd9ee1f0413 in Cppyy::CallR (method=<optimized out>, self=<optimized out>, nargs=<optimized out>, args=<optimized out>) at src/clingwrapper.cxx:916
#14 0x00007fd9ec0501df in CPyCppyy::(anonymous namespace)::InstanceRefExecutor::Execute (this=0x5609e7efcd50, method=<optimized out>, self=<optimized out>, ctxt=<optimized out>) at src/Executors.cxx:624
#15 0x00007fd9ec025c79 in CPyCppyy::CPPMethod::ExecuteFast (ctxt=0x7fffa9e5e040, offset=0, self=0x0, this=0x5609e8b509d0) at src/CPPMethod.cxx:853
#16 CPyCppyy::CPPMethod::Execute (this=this
entry=0x5609e8b509d0, self=self
entry=0x0, offset=offset
entry=0, ctxt=ctxt
entry=0x7fffa9e5e040) at src/CPPMethod.cxx:853
#17 0x00007fd9ec0209bf in CPyCppyy::CPPFunction::Call (this=0x5609e8b509d0, self=
0x7fd9eb61aa90: 0x0, args=<optimized out>, nargsf=<optimized out>, kwds=<optimized out>, ctxt=0x7fffa9e5e040) at src/CPPFunction.cxx:89
#18 0x00007fd9ec02ae40 in CPyCppyy::(anonymous namespace)::mp_vectorcall (pymeth=0x7fd9eb61aa80, args=0x7fffa9e5e1f0, nargsf=2, kwds=0x0) at src/CPPOverload.cxx:637
#19 0x00005609dff6b979 in _PyObject_VectorcallTstate (kwnames=0x0, nargsf=2, args=0x7fffa9e5e1f0, callable=0x7fd9eb61aa80, tstate=0x5609e04e9250) at ./Include/cpython/abstract.h:118
#20 object_vacall (tstate=0x5609e04e9250, base=base
entry=0x0, callable=callable
entry=0x7fd9eb61aa80, vargs=vargs
entry=0x7fffa9e5e268) at Objects/call.c:792
#21 0x00005609dff6db6b in PyObject_CallFunctionObjArgs (callable=callable
entry=0x7fd9eb61aa80) at Objects/call.c:899
#22 0x00007fd9ec023e72 in CPyCppyy::op_str_internal (isBound=false, lshift=0x7fd9eb61aa80, pyobj=0x7fd9eb61b300) at src/CPPInstance.cxx:594
#23 CPyCppyy::op_str (self=0x7fd9eb61b300) at src/CPPInstance.cxx:664
#24 0x00005609dffa6997 in PyObject_Str (v=0x7fd9eb61b300) at Objects/object.c:479
#25 PyObject_Str (v=0x7fd9eb61b300) at Objects/object.c:442
#26 0x00005609e0104965 in PyFile_WriteObject (v=0x7fd9eb61b300, f=<optimized out>, flags=flags
entry=1) at Objects/fileobject.c:132
#27 0x00005609e013cc27 in builtin_print (self=<optimized out>, args=0x7fd9f2e3e980, nargs=1, kwnames=<optimized out>) at Python/bltinmodule.c:1874
#28 0x00005609e010ac0a in cfunction_vectorcall_FASTCALL_KEYWORDS (func=0x7fd9f2f07400, args=0x7fd9f2e3e980, nargsf=<optimized out>, kwnames=<optimized out>) at Objects/methodobject.c:446
#29 0x00005609dff58415 in _PyObject_VectorcallTstate (kwnames=0x0, nargsf=<optimized out>, args=0x7fd9f2e3e980, callable=0x7fd9f2f07400, tstate=0x5609e04e9250) at ./Include/cpython/abstract.h:118
#30 PyObject_Vectorcall (kwnames=0x0, nargsf=<optimized out>, args=0x7fd9f2e3e980, callable=0x7fd9f2f07400) at ./Include/cpython/abstract.h:127
#31 call_function (kwnames=0x0, oparg=<optimized out>, pp_stack=<synthetic pointer>, tstate=<optimized out>) at Python/ceval.c:5075
#32 _PyEval_EvalFrameDefault (tstate=<optimized out>, f=<optimized out>, throwflag=<optimized out>) at Python/ceval.c:3518
#33 0x00005609e001d055 in _PyEval_EvalFrame (throwflag=0, f=0x7fd9f2e3e810, tstate=0x5609e04e9250) at ./Include/internal/pycore_ceval.h:40
#34 _PyEval_EvalCode (tstate=0x5609e04e9250, _co=_co
entry=0x7fd9f2eb0870, globals=globals
entry=0x7fd9f2eaa340, locals=locals
entry=0x7fd9f2eaa340, args=args
entry=0x0, argcount=argcount
entry=0, kwnames=0x0, kwargs=0x0, kwcount=0, kwstep=2, defs=0x0, defcount=0, kwdefs=0x0, closure=0x0, name=0x0, qualname=0x0) at Python/ceval.c:4327
#35 0x00005609e001d386 in _PyEval_EvalCodeWithName (qualname=0x0, name=0x0, closure=0x0, kwdefs=0x0, defcount=0, defs=0x0, kwstep=2, kwcount=0, kwargs=0x0, kwnames=0x0, argcount=0, args=0x0, locals=0x7fd9f2eaa340, globals=0x7fd9f2eaa340, _co=0x7fd9f2eb0870) at Python/ceval.c:4359
#36 PyEval_EvalCodeEx (closure=0x0, kwdefs=0x0, defcount=0, defs=0x0, kwcount=0, kws=0x0, argcount=0, args=0x0, locals=0x7fd9f2eaa340, globals=0x7fd9f2eaa340, _co=0x7fd9f2eb0870) at Python/ceval.c:4375
#37 PyEval_EvalCode (co=co
entry=0x7fd9f2eb0870, globals=globals
entry=0x7fd9f2eaa340, locals=locals
entry=0x7fd9f2eaa340) at Python/ceval.c:826
#38 0x00005609e005a937 in run_eval_code_obj (locals=0x7fd9f2eaa340, globals=0x7fd9f2eaa340, co=0x7fd9f2eb0870, tstate=0x5609e04e9250) at Python/pythonrun.c:1219
#39 run_mod (mod=mod
entry=0x5609e95dddc8, filename=filename
entry=0x7fd9f2e35af0, globals=0x7fd9f2eaa340, locals=0x7fd9f2eaa340, flags=flags
entry=0x7fffa9e5ea08, arena=arena
entry=0x7fd9f2e45bb0) at Python/pythonrun.c:1240
#40 0x00005609e005c0c0 in PyRun_InteractiveOneObjectEx (fp=fp
entry=0x7fd9f341aa00 <_IO_2_1_stdin_>, filename=filename
entry=0x7fd9f2e35af0, flags=flags
entry=0x7fffa9e5ea08) at Python/pythonrun.c:273
#41 0x00005609e005c366 in PyRun_InteractiveLoopFlags (fp=fp
entry=0x7fd9f341aa00 <_IO_2_1_stdin_>, filename_str=filename_str
entry=0x5609e0162132 "<stdin>", flags=flags
entry=0x7fffa9e5ea08) at Python/pythonrun.c:126
#42 0x00005609e005ccbe in PyRun_AnyFileExFlags (fp=0x7fd9f341aa00 <_IO_2_1_stdin_>, filename=filename
entry=0x5609e0162132 "<stdin>", closeit=closeit
entry=0, flags=flags
entry=0x7fffa9e5ea08) at Python/pythonrun.c:85
#43 0x00005609dff5ec59 in pymain_run_stdin (cf=0x7fffa9e5ea08, config=0x5609e04e7b40) at Modules/main.c:512
#44 pymain_run_python (exitcode=exitcode
entry=0x7fffa9e5eb30) at Modules/main.c:601
#45 0x00005609dff5f038 in Py_RunMain () at Modules/main.c:677
#46 pymain_main (args=0x7fffa9e5eaf0) at Modules/main.c:707
#47 Py_BytesMain (argc=<optimized out>, argv=<optimized out>) at Modules/main.c:731
#48 0x00007fd9f328309b in __libc_start_main (main=0x5609dff526d0 <main>, argc=1, argv=0x7fffa9e5ec38, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7fffa9e5ec28) at ../csu/libc-start.c:308
#49 0x00005609dff5dcfa in _start () at ./Include/object.h:430

@wlav
Copy link
Owner

wlav commented Sep 29, 2021

For the iterator container, since it returns iterators, instead of their pointees, that seems the correct behavior. Note that dereferencing is automatic if you access something on the iterator that does not exist on it but does exit on the pointee.

For the crash, below is a standalone reproducer. The problem is purely to do with having a const& data member, which returns an incorrect address (and it's downhill from there):

import cppyy

cppyy.cppdef("""\
namespace ConstRefData {
struct A {
    std::string name;
};

A gA{"Hello, World!"};

struct B {
    B() : body1(gA), body2(gA) {}
    A body1;
    const A& body2;
}; }""")

ns = cppyy.gbl.ConstRefData

b = ns.B()

assert b.body1.name == b.body2.name

@DillanCMills
Copy link
Author

Awesome, it is nice knowing there is an identified issue. So is this something that needs to be changed in the C++, or in my python code? Or is it a bug in cppyy? I am not familiar with why this would cause an incorrect address so I apologize if the solution might be obvious.

@wlav
Copy link
Owner

wlav commented Sep 29, 2021

It's a bug in cppyy. It has an easy fix, but that breaks some other behavior that relies on things being the way they are. The two uses seem incompatible: when passing an object by reference through JITed code, it is a single pointer (void*), when retrieving the data member address from Cling, it has a double pointer (void**). So, one or the other usage needs adjustment. Not sure yet which is least invasive.

@DillanCMills
Copy link
Author

Okay, I will wait for resolution then.

@wlav
Copy link
Owner

wlav commented Sep 29, 2021

This should do it:
wlav/CPyCppyy@bcac5d0

@DillanCMills
Copy link
Author

It works! Thanks a lot, I will keep moving forward and hopefully don't hit any more issues.

How did you identify the problem? Just curious.

Also, to close out the iterator topic, since it is a container, that means I won't be able to do a for x in obj type loop? Would I be able to do that on the returned value since it is an iterator? Otherwise, I can at least do a for x in range(obj.size()) which is probably sufficient.

@wlav
Copy link
Owner

wlav commented Sep 29, 2021

How did you identify the problem? Just curious.

I finally had the time to click on the link above. The cppyy tests are extensive, but there was no test for const-ref data members, so that was a logical thing to try. After all: what isn't tested, is broken.

I'm not understanding why the iterator loop doesn't work. The code in Pythonize.cxx to figure this out is a bit elaborate: there are a couple of things that need to cooperate for the iterator protocol in Python to work, and somehow this case fails at least one of them. What I think is different here than otherwise, is that the result of members(), namely iterator_range<iterator>, is a container of iterators rather than a container of some other objects. I can try to reproduce, but lack time atm.

@DillanCMills
Copy link
Author

Okay thanks. That is not as big of an issue since I have a reasonable workaround, but for the sake of the project I assume it would be a good fix to have eventually. Thanks for the hard work, this is an extremely impressive tool.

@wlav
Copy link
Owner

wlav commented Sep 30, 2021

Fixed in repo: wlav/CPyCppyy@d0bc640

It's indeed only for this particular case.

@DillanCMills
Copy link
Author

Awesome 2-for-1, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants