wlav / cppyy

Other
391 stars 40 forks source link

Problems with std::tuple containing pointers #109

Closed N-Coder closed 9 months ago

N-Coder commented 1 year ago

This is probably similar to this issue on Bitbucket, although it is happing in possibly far more common context. Consider a vector of tuples containing pointers:

>>> import cppyy
>>> 
>>> cppyy.cppexec("""
... #include <tuple>
... #include <vector>
... #include <string>
... 
... std::vector<std::tuple<int*, std::string*>> list;
... int i = 5;
... std::string s = "test";
... 
... list.emplace_back(&i, &s); // int -> int*
... """)
True
>>> g = cppyy.gbl

Calling emplace_back from Python selects <int, string> as template arguments and then fails to find a std::tuple<int*, string*>(int&, string&) constructor at the linker step. Also, this error doesn't seem to raise an exception, as there still is an (invalid) value that is returned.

>>> g.list.emplace_back(g.i, g.s)
IncrementalExecutor::executeFunction: symbol '_ZNSt15__new_allocatorISt5tupleIJPiPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEEE9constructIS9_JiRS7_EEEvPT_DpOT0_' unresolved while linking symbol '__cf_4'!
You are probably missing the definition of void std::__new_allocator<std::tuple<int*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*> >::construct<std::tuple<int*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*>, int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&>(std::tuple<int*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*>*, int&&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&)
Maybe you need to load the corresponding shared library?
<cppyy.gbl.std.tuple<int*,std::string*> object at 0x(nil)>

Manually setting the template arguments fails with a conversion error:

>>> g.list.emplace_back["int*", "std::string*"](g.i, g.s)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: Could not find "emplace_back<int*,std::string*>" (set cppyy.set_debug() for C++ errors):
  std::tuple<int*,std::string*>& std::vector<std::tuple<int*,std::string*> >::emplace_back(int*&& __args, std::string*&& __args) =>
    TypeError: could not convert argument 1

Same for calling make_tuple<int*, std::string*>:

>>> g.list.push_back(g.std.make_tuple["int*", "std::string*"](g.i, g.s))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: Could not find "make_tuple<int*,std::string*>" (set cppyy.set_debug() for C++ errors):
  std::tuple<int*,std::string*> std::make_tuple(int*&& __args, std::string*&& __args) =>
    TypeError: could not convert argument 1
wlav commented 1 year ago

Hmm, in that bitbucket issue I'm complaining about shortage of time b/c of a big conference, another iteration of which recently absorbed all my time again. :)

Nothing obvious jumps out for the first case: Cling is first queried for the existence of a method, before an implementation is attempted. I don't understand how the emplace_back instantiation can have succeeded for the non-pointer types.

The second case (*&&) should be easy to fix. There simply isn't a converter for it, but it's a trivial one.

wlav commented 1 year ago

Sorry for being dense, but I missed that g.i is never going to pass through a int*. Has to be ctypes.pointer of ctypes.c_int. The reason is that g.i is a Python int, so not addressable (globals are implemented as Python property objects).

When using ctypes, it still fails b/c there's a match to std::string& from Cling, rather than std::string*, so the same problem is still there. However, if you provide the arguments explicitly (i.e. 'int*, std::string*'), then it does work, so there's at least a workaround.

wlav commented 9 months ago

Closing as clarified.

N-Coder commented 9 months ago

Note that the first python expression now no longer fails with a linker warning but a segmentation fault:

>>> g.list.emplace_back(g.i, g.s)
In file included from /tmp/pip-build-env-iprf7o9c/normal/lib/python3.12/site-packages/cppyy_backend/input_line_3:2:
In file included from /usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/string:54:
In file included from /usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/basic_string.h:39:
In file included from /usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/ext/alloc_traits.h:34:
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/alloc_traits.h:539:4: error: cannot compile this l-value expression yet
          std::construct_at(__p, std::forward<_Args>(__args)...);
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 *** Break *** segmentation violation
#0  0x00007fef5d31ccc7 in wait4 () from /lib64/libc.so.6
#1  0x00007fef5d26e21b in do_system () from /lib64/libc.so.6
#2  0x00007fef4f558c15 in CppyyLegacy::TUnixSystem::StackTrace() () from /tmp/venv/lib64/python3.12/site-packages/cppyy_backend/lib/libCoreLegacy.so
#3  0x00007fef4f2feda3 in (anonymous namespace)::TExceptionHandlerImp::HandleException(int) () from /tmp/venv/lib64/python3.12/site-packages/cppyy_backend/lib/libcppyy_backend.so
#4  0x00007fef4f5576f1 in CppyyLegacy::TUnixSystem::DispatchSignals(CppyyLegacy::ESignals) () from /tmp/venv/lib64/python3.12/site-packages/cppyy_backend/lib/libCoreLegacy.so
#5  <signal handler called>
#6  0x00007fef4d6c9464 in llvm::PointerType::get(llvm::Type*, unsigned int) () from /tmp/venv/lib64/python3.12/site-packages/cppyy_backend/lib/libCling.so
#7  0x00007fef4a1f8e99 in clang::CodeGen::CodeGenFunction::EmitUnsupportedLValue(clang::Expr const*, char const*) () from /tmp/venv/lib64/python3.12/site-packages/cppyy_backend/lib/libCling.so
#8  0x00007fef4a20e3e5 in clang::CodeGen::CodeGenFunction::EmitLValue(clang::Expr const*) () from /tmp/venv/lib64/python3.12/site-packages/cppyy_backend/lib/libCling.so
#9  0x00007fef4a20eb3b in clang::CodeGen::CodeGenFunction::EmitIgnoredExpr(clang::Expr const*) () from /tmp/venv/lib64/python3.12/site-packages/cppyy_backend/lib/libCling.so
#10 0x00007fef49efa9ce in clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) () from /tmp/venv/lib64/python3.12/site-packages/cppyy_backend/lib/libCling.so
#11 0x00007fef49efaffa in clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) () from /tmp/venv/lib64/python3.12/site-packages/cppyy_backend/lib/libCling.so
#12 0x00007fef49f56cca in clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::Stmt const*) () from /tmp/venv/lib64/python3.12/site-packages/cppyy_backend/lib/libCling.so
#13 0x00007fef49f613a5 in clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) () from /tmp/venv/lib64/python3.12/site-packages/cppyy_backend/lib/libCling.so
#14 0x00007fef49fab97b in clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) () from /tmp/venv/lib64/python3.12/site-packages/cppyy_backend/lib/libCling.so
#15 0x00007fef49fa9213 in clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) () from /tmp/venv/lib64/python3.12/site-packages/cppyy_backend/lib/libCling.so
#16 0x00007fef49fb1799 in clang::CodeGen::CodeGenModule::EmitDeferred() () from /tmp/venv/lib64/python3.12/site-packages/cppyy_backend/lib/libCling.so
#17 0x00007fef49fb17b1 in clang::CodeGen::CodeGenModule::EmitDeferred() () from /tmp/venv/lib64/python3.12/site-packages/cppyy_backend/lib/libCling.so
#18 0x00007fef49fb397e in clang::CodeGen::CodeGenModule::Release() () from /tmp/venv/lib64/python3.12/site-packages/cppyy_backend/lib/libCling.so
#19 0x00007fef49ea3c9a in clang::CodeGeneratorImpl::HandleTranslationUnit(clang::ASTContext&) () from /tmp/venv/lib64/python3.12/site-packages/cppyy_backend/lib/libCling.so
#20 0x00007fef49e3873a in cling::IncrementalParser::codeGenTransaction(cling::Transaction*) () from /tmp/venv/lib64/python3.12/site-packages/cppyy_backend/lib/libCling.so
#21 0x00007fef49e38a25 in cling::IncrementalParser::commitTransaction(llvm::PointerIntPair<cling::Transaction*, 2u, cling::IncrementalParser::EParseResult, llvm::PointerLikeTypeTraits<cling::Transaction*>, llvm::PointerIntPairInfo<cling::Transaction*, 2u, llvm::PointerLikeTypeTraits<cling::Transaction*> > >&, bool) () from /tmp/venv/lib64/python3.12/site-packages/cppyy_backend/lib/libCling.so
#22 0x00007fef49e3c6f9 in cling::IncrementalParser::Compile(llvm::StringRef, cling::CompilationOptions const&) () from /tmp/venv/lib64/python3.12/site-packages/cppyy_backend/lib/libCling.so
#23 0x00007fef49d978d2 in cling::Interpreter::declare(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cling::Transaction**) () from /tmp/venv/lib64/python3.12/site-packages/cppyy_backend/lib/libCling.so
#24 0x00007fef49d97a8e in cling::Interpreter::DeclareCFunction(llvm::StringRef, llvm::StringRef, bool, cling::Transaction*&) () from /tmp/venv/lib64/python3.12/site-packages/cppyy_backend/lib/libCling.so
#25 0x00007fef49d97c4e in cling::Interpreter::compileFunction(llvm::StringRef, llvm::StringRef, bool, bool) () from /tmp/venv/lib64/python3.12/site-packages/cppyy_backend/lib/libCling.so
#26 0x00007fef49c91561 in CppyyLegacy::TClingCallFunc::make_wrapper(bool) () from /tmp/venv/lib64/python3.12/site-packages/cppyy_backend/lib/libCling.so
#27 0x00007fef49c91aec in CppyyLegacy::TClingCallFunc::IFacePtr(bool) () from /tmp/venv/lib64/python3.12/site-packages/cppyy_backend/lib/libCling.so
#28 0x00007fef49c9de60 in CppyyLegacy::TCling::CallFunc_IFacePtr(CppyyLegacy::CallFunc_t*, bool) const () from /tmp/venv/lib64/python3.12/site-packages/cppyy_backend/lib/libCling.so
#29 0x00007fef4f306ae5 in WrapperCall(long, unsigned long, void*, void*, void*) () from /tmp/venv/lib64/python3.12/site-packages/cppyy_backend/lib/libcppyy_backend.so
#30 0x00007fef4f306fb7 in Cppyy::CallR(long, void*, unsigned long, void*) () from /tmp/venv/lib64/python3.12/site-packages/cppyy_backend/lib/libcppyy_backend.so
#31 0x00007fef4642ef2a in CPyCppyy::(anonymous namespace)::InstanceRefExecutor::Execute(long, void*, CPyCppyy::CallContext*) () from /tmp/venv/lib64/python3.12/site-packages/libcppyy.cpython-312-x86_64-linux-gnu.so
#32 0x00007fef463e3757 in CPyCppyy::CPPMethod::ExecuteFast(void*, long, CPyCppyy::CallContext*) [clone .isra.0] () from /tmp/venv/lib64/python3.12/site-packages/libcppyy.cpython-312-x86_64-linux-gnu.so
#33 0x00007fef463e37d6 in CPyCppyy::CPPMethod::Execute(void*, long, CPyCppyy::CallContext*) () from /tmp/venv/lib64/python3.12/site-packages/libcppyy.cpython-312-x86_64-linux-gnu.so
#34 0x00007fef463e3cdf in CPyCppyy::CPPMethod::Call(CPyCppyy::CPPInstance*&, _object* const*, unsigned long, _object*, CPyCppyy::CallContext*) () from /tmp/venv/lib64/python3.12/site-packages/libcppyy.cpython-312-x86_64-linux-gnu.so
#35 0x00007fef463eaa66 in CPyCppyy::(anonymous namespace)::mp_vectorcall(CPyCppyy::CPPOverload*, _object* const*, unsigned long, _object*) () from /tmp/venv/lib64/python3.12/site-packages/libcppyy.cpython-312-x86_64-linux-gnu.so
#36 0x00007fef46457a31 in CPyCppyy::CallMethodImp(CPyCppyy::TemplateProxy*, _object*&, _object* const*, unsigned long, _object*, bool, unsigned long) () from /tmp/venv/lib64/python3.12/site-packages/libcppyy.cpython-312-x86_64-linux-gnu.so
#37 0x00007fef4645858e in CPyCppyy::tpp_vectorcall(CPyCppyy::TemplateProxy*, _object* const*, unsigned long, _object*) () from /tmp/venv/lib64/python3.12/site-packages/libcppyy.cpython-312-x86_64-linux-gnu.so
#38 0x00007fef5d6084cc in PyObject_Vectorcall () from /lib64/libpython3.12.so.1.0
#39 0x00007fef5d50f588 in _PyEval_EvalFrameDefault.cold () from /lib64/libpython3.12.so.1.0
#40 0x00007fef5d687876 in PyEval_EvalCode () from /lib64/libpython3.12.so.1.0
#41 0x00007fef5d6aad9a in run_eval_code_obj () from /lib64/libpython3.12.so.1.0
#42 0x00007fef5d6a5ebe in run_mod () from /lib64/libpython3.12.so.1.0
#43 0x00007fef5d5de8b0 in PyRun_InteractiveOneObjectEx () from /lib64/libpython3.12.so.1.0
#44 0x00007fef5d5df994 in _PyRun_InteractiveLoopObject () from /lib64/libpython3.12.so.1.0
#45 0x00007fef5d5512dc in _PyRun_AnyFileObject.cold () from /lib64/libpython3.12.so.1.0
#46 0x00007fef5d5dfb10 in PyRun_AnyFileExFlags () from /lib64/libpython3.12.so.1.0
#47 0x00007fef5d54696f in Py_RunMain.cold () from /lib64/libpython3.12.so.1.0
#48 0x00007fef5d67185c in Py_BytesMain () from /lib64/libpython3.12.so.1.0
#49 0x00007fef5d24614a in __libc_start_call_main () from /lib64/libc.so.6
#50 0x00007fef5d24620b in __libc_start_main_impl () from /lib64/libc.so.6
#51 0x0000564fc493c095 in _start ()
 *** Break *** segmentation violation
#0  0x00007fef5d31ccc7 in wait4 () from /lib64/libc.so.6
#1  0x00007fef5d26e21b in do_system () from /lib64/libc.so.6
#2  0x00007fef4f558c15 in CppyyLegacy::TUnixSystem::StackTrace() () from /tmp/venv/lib64/python3.12/site-packages/cppyy_backend/lib/libCoreLegacy.so
#3  0x00007fef4f2fec27 in (anonymous namespace)::TExceptionHandlerImp::HandleException(int) () from /tmp/venv/lib64/python3.12/site-packages/cppyy_backend/lib/libcppyy_backend.so
#4  0x00007fef4f5576f1 in CppyyLegacy::TUnixSystem::DispatchSignals(CppyyLegacy::ESignals) () from /tmp/venv/lib64/python3.12/site-packages/cppyy_backend/lib/libCoreLegacy.so
#5  <signal handler called>
#6  0x00007fef4d6c9464 in llvm::PointerType::get(llvm::Type*, unsigned int) () from /tmp/venv/lib64/python3.12/site-packages/cppyy_backend/lib/libCling.so
#7  0x00007fef4a1f8e99 in clang::CodeGen::CodeGenFunction::EmitUnsupportedLValue(clang::Expr const*, char const*) () from /tmp/venv/lib64/python3.12/site-packages/cppyy_backend/lib/libCling.so
#8  0x00007fef4a20e3e5 in clang::CodeGen::CodeGenFunction::EmitLValue(clang::Expr const*) () from /tmp/venv/lib64/python3.12/site-packages/cppyy_backend/lib/libCling.so
#9  0x00007fef4a20eb3b in clang::CodeGen::CodeGenFunction::EmitIgnoredExpr(clang::Expr const*) () from /tmp/venv/lib64/python3.12/site-packages/cppyy_backend/lib/libCling.so
#10 0x00007fef49efa9ce in clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) () from /tmp/venv/lib64/python3.12/site-packages/cppyy_backend/lib/libCling.so
#11 0x00007fef49efaffa in clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) () from /tmp/venv/lib64/python3.12/site-packages/cppyy_backend/lib/libCling.so
#12 0x00007fef49f56cca in clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::Stmt const*) () from /tmp/venv/lib64/python3.12/site-packages/cppyy_backend/lib/libCling.so
#13 0x00007fef49f613a5 in clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) () from /tmp/venv/lib64/python3.12/site-packages/cppyy_backend/lib/libCling.so
#14 0x00007fef49fab97b in clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) () from /tmp/venv/lib64/python3.12/site-packages/cppyy_backend/lib/libCling.so
#15 0x00007fef49fa9213 in clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) () from /tmp/venv/lib64/python3.12/site-packages/cppyy_backend/lib/libCling.so
#16 0x00007fef49fb1799 in clang::CodeGen::CodeGenModule::EmitDeferred() () from /tmp/venv/lib64/python3.12/site-packages/cppyy_backend/lib/libCling.so
#17 0x00007fef49fb17b1 in clang::CodeGen::CodeGenModule::EmitDeferred() () from /tmp/venv/lib64/python3.12/site-packages/cppyy_backend/lib/libCling.so
#18 0x00007fef49fb397e in clang::CodeGen::CodeGenModule::Release() () from /tmp/venv/lib64/python3.12/site-packages/cppyy_backend/lib/libCling.so
#19 0x00007fef49ea3c9a in clang::CodeGeneratorImpl::HandleTranslationUnit(clang::ASTContext&) () from /tmp/venv/lib64/python3.12/site-packages/cppyy_backend/lib/libCling.so
#20 0x00007fef49e3873a in cling::IncrementalParser::codeGenTransaction(cling::Transaction*) () from /tmp/venv/lib64/python3.12/site-packages/cppyy_backend/lib/libCling.so
#21 0x00007fef49e38a25 in cling::IncrementalParser::commitTransaction(llvm::PointerIntPair<cling::Transaction*, 2u, cling::IncrementalParser::EParseResult, llvm::PointerLikeTypeTraits<cling::Transaction*>, llvm::PointerIntPairInfo<cling::Transaction*, 2u, llvm::PointerLikeTypeTraits<cling::Transaction*> > >&, bool) () from /tmp/venv/lib64/python3.12/site-packages/cppyy_backend/lib/libCling.so
#22 0x00007fef49e3c6f9 in cling::IncrementalParser::Compile(llvm::StringRef, cling::CompilationOptions const&) () from /tmp/venv/lib64/python3.12/site-packages/cppyy_backend/lib/libCling.so
#23 0x00007fef49d978d2 in cling::Interpreter::declare(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cling::Transaction**) () from /tmp/venv/lib64/python3.12/site-packages/cppyy_backend/lib/libCling.so
#24 0x00007fef49d97a8e in cling::Interpreter::DeclareCFunction(llvm::StringRef, llvm::StringRef, bool, cling::Transaction*&) () from /tmp/venv/lib64/python3.12/site-packages/cppyy_backend/lib/libCling.so
#25 0x00007fef49d97c4e in cling::Interpreter::compileFunction(llvm::StringRef, llvm::StringRef, bool, bool) () from /tmp/venv/lib64/python3.12/site-packages/cppyy_backend/lib/libCling.so
#26 0x00007fef49c91561 in CppyyLegacy::TClingCallFunc::make_wrapper(bool) () from /tmp/venv/lib64/python3.12/site-packages/cppyy_backend/lib/libCling.so
#27 0x00007fef49c91aec in CppyyLegacy::TClingCallFunc::IFacePtr(bool) () from /tmp/venv/lib64/python3.12/site-packages/cppyy_backend/lib/libCling.so
#28 0x00007fef49c9de60 in CppyyLegacy::TCling::CallFunc_IFacePtr(CppyyLegacy::CallFunc_t*, bool) const () from /tmp/venv/lib64/python3.12/site-packages/cppyy_backend/lib/libCling.so
#29 0x00007fef4f306ae5 in WrapperCall(long, unsigned long, void*, void*, void*) () from /tmp/venv/lib64/python3.12/site-packages/cppyy_backend/lib/libcppyy_backend.so
#30 0x00007fef4f306fb7 in Cppyy::CallR(long, void*, unsigned long, void*) () from /tmp/venv/lib64/python3.12/site-packages/cppyy_backend/lib/libcppyy_backend.so
#31 0x00007fef4642ef2a in CPyCppyy::(anonymous namespace)::InstanceRefExecutor::Execute(long, void*, CPyCppyy::CallContext*) () from /tmp/venv/lib64/python3.12/site-packages/libcppyy.cpython-312-x86_64-linux-gnu.so
#32 0x00007fef463e3757 in CPyCppyy::CPPMethod::ExecuteFast(void*, long, CPyCppyy::CallContext*) [clone .isra.0] () from /tmp/venv/lib64/python3.12/site-packages/libcppyy.cpython-312-x86_64-linux-gnu.so
#33 0x00007fef463e37d6 in CPyCppyy::CPPMethod::Execute(void*, long, CPyCppyy::CallContext*) () from /tmp/venv/lib64/python3.12/site-packages/libcppyy.cpython-312-x86_64-linux-gnu.so
#34 0x00007fef463e3cdf in CPyCppyy::CPPMethod::Call(CPyCppyy::CPPInstance*&, _object* const*, unsigned long, _object*, CPyCppyy::CallContext*) () from /tmp/venv/lib64/python3.12/site-packages/libcppyy.cpython-312-x86_64-linux-gnu.so
#35 0x00007fef463eaa66 in CPyCppyy::(anonymous namespace)::mp_vectorcall(CPyCppyy::CPPOverload*, _object* const*, unsigned long, _object*) () from /tmp/venv/lib64/python3.12/site-packages/libcppyy.cpython-312-x86_64-linux-gnu.so
#36 0x00007fef46457a31 in CPyCppyy::CallMethodImp(CPyCppyy::TemplateProxy*, _object*&, _object* const*, unsigned long, _object*, bool, unsigned long) () from /tmp/venv/lib64/python3.12/site-packages/libcppyy.cpython-312-x86_64-linux-gnu.so
#37 0x00007fef4645858e in CPyCppyy::tpp_vectorcall(CPyCppyy::TemplateProxy*, _object* const*, unsigned long, _object*) () from /tmp/venv/lib64/python3.12/site-packages/libcppyy.cpython-312-x86_64-linux-gnu.so
#38 0x00007fef5d6084cc in PyObject_Vectorcall () from /lib64/libpython3.12.so.1.0
#39 0x00007fef5d50f588 in _PyEval_EvalFrameDefault.cold () from /lib64/libpython3.12.so.1.0
#40 0x00007fef5d687876 in PyEval_EvalCode () from /lib64/libpython3.12.so.1.0
#41 0x00007fef5d6aad9a in run_eval_code_obj () from /lib64/libpython3.12.so.1.0
#42 0x00007fef5d6a5ebe in run_mod () from /lib64/libpython3.12.so.1.0
#43 0x00007fef5d5de8b0 in PyRun_InteractiveOneObjectEx () from /lib64/libpython3.12.so.1.0
#44 0x00007fef5d5df994 in _PyRun_InteractiveLoopObject () from /lib64/libpython3.12.so.1.0
#45 0x00007fef5d5512dc in _PyRun_AnyFileObject.cold () from /lib64/libpython3.12.so.1.0
#46 0x00007fef5d5dfb10 in PyRun_AnyFileExFlags () from /lib64/libpython3.12.so.1.0
#47 0x00007fef5d54696f in Py_RunMain.cold () from /lib64/libpython3.12.so.1.0
#48 0x00007fef5d67185c in Py_BytesMain () from /lib64/libpython3.12.so.1.0
#49 0x00007fef5d24614a in __libc_start_call_main () from /lib64/libc.so.6
#50 0x00007fef5d24620b in __libc_start_main_impl () from /lib64/libc.so.6
#51 0x0000564fc493c095 in _start ()

(For the other two the error is still the same.)

wlav commented 9 months ago

Which platform? I'm still getting the same missing symbol error on Ubuntu.

And to reiterate, it's not possible to take a pointer to a Pythonint (there's no "int-style" memory to point to). Best I can think of, is to change cppyy.addressof() to be able to give the address of a global variable (as it can do for class members), e.g. like cppyy.addressof(cppyy.gbl, 'i') then use that value through ctypes to construct an int*. Not going to be pretty not matter what.

N-Coder commented 9 months ago

Fedora 39. It's not that this I'm expecting this to work given your explanation, but it probably shouldn't crash either. While this is only a very minor issue in this specific case as the usage here is broken, the crash might be annoying in other circumstances.