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

Unable to pass python callback to C++ #175

Open
dyershov opened this issue Jul 10, 2023 · 30 comments
Open

Unable to pass python callback to C++ #175

dyershov opened this issue Jul 10, 2023 · 30 comments

Comments

@dyershov
Copy link

dyershov commented Jul 10, 2023

My issue might be related to #156

I installed cppyy==3.0.0 inside a virtual environment using virtualenvwrapper. The following code from cppyy examples fails:

import cppyy

cppyy.cppdef(r"""
int call_int_int(int (*f)(int, int), int i1, int i2) {
    return f(i1, i2);
}
""")

from cppyy.gbl import call_int_int
print(call_int_int.__doc__)

def add(a, b):
    return a + b

call_int_int(add, 3, 7)
call_int_int(lambda x, y: x*y, 3, 7)

The error messages are:

int ::call_int_int(int(*)(int,int) f, int i1, int i2)
cling JIT session error: Failed to materialize symbols: { (main, { _ZN16__cppyy_internal10fptr_wrap1Eii }) }
Traceback (most recent call last):
  File "/home/yershov/SynologyDrive/code/emp/experiments/callback.py", line 16, in <module>
    call_int_int(add, 3, 7)
TypeError: int ::call_int_int(int(*)(int,int) f, int i1, int i2) =>
    TypeError: could not convert argument 1
@wlav
Copy link
Owner

wlav commented Jul 10, 2023

Yes, looks like the same bug.

My problem remains reproducing the error. Do you have more details, e.g. platform, compiler version, etc.?

@dyershov
Copy link
Author

dyershov commented Jul 10, 2023

A few updates. First, the bug persists even after installing cppyy from sources, i.e., rebuilding the backend from scratch.

Second, I'm using Arch Linux with both gcc and clang installed:

Details here
 % gcc --version 
gcc (GCC) 13.1.1 20230429
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

 % clang --version
clang version 15.0.7
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

 % python --version
Python 3.11.3

 % pip freeze
anyio==3.7.1
argon2-cffi==21.3.0
argon2-cffi-bindings==21.2.0
arrow==1.2.3
asttokens==2.2.1
async-lru==2.0.3
attrs==23.1.0
Babel==2.12.1
backcall==0.2.0
beautifulsoup4==4.12.2
bleach==6.0.0
certifi==2023.5.7
cffi==1.15.1
charset-normalizer==3.2.0
cloudpickle==2.2.1
comm==0.1.3
contourpy==1.1.0
cppyy==3.0.0
cppyy-backend==1.14.11
cppyy-cling==6.28.0
CPyCppyy==1.12.13
cycler==0.11.0
debugpy==1.6.7
decorator==5.1.1
defusedxml==0.7.1
executing==1.2.0
fastjsonschema==2.17.1
fonttools==4.40.0
fqdn==1.5.1
idna==3.4
ipykernel==6.24.0
ipython==8.14.0
ipython-genutils==0.2.0
ipywidgets==8.0.7
isoduration==20.11.0
jedi==0.18.2
Jinja2==3.1.2
json5==0.9.14
jsonpointer==2.4
jsonschema==4.18.0
jsonschema-specifications==2023.6.1
jupyter==1.0.0
jupyter-console==6.6.3
jupyter-events==0.6.3
jupyter-lsp==2.2.0
jupyter_client==8.3.0
jupyter_core==5.3.1
jupyter_server==2.7.0
jupyter_server_terminals==0.4.4
jupyterlab==4.0.2
jupyterlab-pygments==0.2.2
jupyterlab-widgets==3.0.8
jupyterlab_server==2.23.0
kiwisolver==1.4.4
markdown-it-py==3.0.0
MarkupSafe==2.1.3
matplotlib==3.7.2
matplotlib-inline==0.1.6
mdurl==0.1.2
mistune==3.0.1
nbclassic==1.0.0
nbclient==0.8.0
nbconvert==7.6.0
nbformat==5.9.1
nest-asyncio==1.5.6
notebook==6.5.4
notebook_shim==0.2.3
numpy==1.25.1
overrides==7.3.1
packaging==23.1
pandocfilters==1.5.0
parso==0.8.3
pexpect==4.8.0
pickleshare==0.7.5
Pillow==10.0.0
platformdirs==3.8.1
prometheus-client==0.17.0
prompt-toolkit==3.0.39
psutil==5.9.5
ptyprocess==0.7.0
pure-eval==0.2.2
pycparser==2.21
Pygments==2.15.1
pynvml==11.4.1
pyparsing==3.0.9
python-dateutil==2.8.2
python-json-logger==2.0.7
PyYAML==6.0
pyzmq==25.1.0
qtconsole==5.4.3
QtPy==2.3.1
referencing==0.29.1
requests==2.31.0
rfc3339-validator==0.1.4
rfc3986-validator==0.1.1
rich==13.4.2
rpds-py==0.8.10
scalene==1.5.21.4
Send2Trash==1.8.2
six==1.16.0
sniffio==1.3.0
soupsieve==2.4.1
stack-data==0.6.2
terminado==0.17.1
tinycss2==1.2.1
tornado==6.3.2
traitlets==5.9.0
uri-template==1.3.0
urllib3==2.0.3
wcwidth==0.2.6
webcolors==1.13
webencodings==0.5.1
websocket-client==1.6.1
widgetsnbextension==4.0.8

Anything else?

@dyershov
Copy link
Author

dyershov commented Jul 11, 2023

@wlav, I found a related issue root-project/root#12294 (comment)

BTW, is it possible to point cling to a custom toolchain, system and STL headers, and compiled objects?

@wlav
Copy link
Owner

wlav commented Jul 11, 2023

The fix for root#12294 is already included in the release, so that can't be it.

For the toolchain, in principle yes: Cling picks up the compiler paths from the system compiler, so either change PATH to point to the new chain or use -I arguments in the EXTRA_CLING_ARGS variable.

@Gabrielcarvfer
Copy link

Gabrielcarvfer commented Jul 20, 2023

@wlav not sure if it helps, but I was testing a different variant from the example @dyershov provided.

import cppyy

cppyy.cppdef("""

template<typename T>
T call_int_int(T (*f)(T,T), T i1, T i2) {
    return f(i1, i2);
}
int sumc(int a, int b)
{
    return a+b;    
}
""")

from cppyy.gbl import call_int_int, sumc

def add(a: int, b: int)->int:
    return a + b

print(call_int_int[int](sumc, 3, 7)) # prints 10 as expected
print(call_int_int[int](add, 3, 7)) # errors out, trace below
Error trace
cling JIT session error: Failed to materialize symbols: { (main, { _ZN16__cppyy_internal10fptr_wrap1Eii }) }
terminate called after throwing an instance of 'std::logic_error'
  what():  basic_string: construction from null is not valid
 *** Break *** abort
#0  0x00007f12622e1687 in __GI___wait4 (pid=42950, stat_loc=stat_loc
entry=0x7ffc06574738, options=options
entry=0, usage=usage
entry=0x0) at ../sysdeps/unix/sysv/linux/wait4.c:30
#1  0x00007f12622e164b in __GI___waitpid (pid=<optimized out>, stat_loc=stat_loc
entry=0x7ffc06574738, options=options
entry=0) at ./posix/waitpid.c:38
#2  0x00007f126224ea5b in do_system (line=<optimized out>) at ../sysdeps/posix/system.c:171
#3  0x00007f12617a0b65 in CppyyLegacy::TUnixSystem::StackTrace() () from /tmp/cppyy3_test/venv/lib/python3.11/site-packages/cppyy_backend/lib/libCoreLegacy.so
#4  0x00007f126195baf3 in (anonymous namespace)::do_trace (sig=5) at src/clingwrapper.cxx:239
#5  (anonymous namespace)::TExceptionHandlerImp::HandleException (this=<optimized out>, sig=5) at src/clingwrapper.cxx:252
#6  0x00007f126179f641 in CppyyLegacy::TUnixSystem::DispatchSignals(CppyyLegacy::ESignals) () from /tmp/cppyy3_test/venv/lib/python3.11/site-packages/cppyy_backend/lib/libCoreLegacy.so
#7  <signal handler called>
#8  __pthread_kill_implementation (no_tid=0, signo=6, threadid=<optimized out>) at ./nptl/pthread_kill.c:44
#9  __pthread_kill_internal (signo=6, threadid=<optimized out>) at ./nptl/pthread_kill.c:78
#10 __GI___pthread_kill (threadid=<optimized out>, signo=signo
entry=6) at ./nptl/pthread_kill.c:89
#11 0x00007f126223c406 in __GI_raise (sig=sig
entry=6) at ../sysdeps/posix/raise.c:26
#12 0x00007f126222287c in __GI_abort () at ./stdlib/abort.c:79
#13 0x00007f12612a4f26 in ?? () from /lib/x86_64-linux-gnu/libstdc++.so.6
#14 0x00007f12612b6f2c in ?? () from /lib/x86_64-linux-gnu/libstdc++.so.6
#15 0x00007f12612b6f97 in std::terminate() () from /lib/x86_64-linux-gnu/libstdc++.so.6
#16 0x00007f12612b71f8 in __cxa_throw () from /lib/x86_64-linux-gnu/libstdc++.so.6
#17 0x00007f12612a814c in std::__throw_logic_error(char const*) () from /lib/x86_64-linux-gnu/libstdc++.so.6
#18 0x00007f1260dc6e2a in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string<std::allocator<char> > (__a=..., __s=0x0, this=0x7ffc06577300) at /usr/include/c++/12/bits/basic_string.h:639
#19 AddTypeName (tmpl_name="<", tn=<optimized out>, arg=<optimized out>, pref=pref
entry=CPyCppyy::Utility::kNone, pcnt=pcnt
entry=0x0) at src/Utility.cxx:509
#20 0x00007f1260dc702e in CPyCppyy::Utility::ConstructTemplateArgs[abi:cxx11](_object*, _object*, _object*, CPyCppyy::Utility::ArgPreference, int, int*) (pyname=pyname
entry=0x0, tpArgs=tpArgs
entry=(<type at remote 0x955020>, <type at remote 0x95dcc0>, <type at remote 0x95dcc0>), args=args
entry=(<function at remote 0x7f12624e04a0>, 3, 7), pref=pref
entry=CPyCppyy::Utility::kNone, argoff=argoff
entry=0, pcnt=0x0) at src/Utility.cxx:589
#21 0x00007f1260dbf395 in CPyCppyy::TemplateProxy::Instantiate (this=this
entry=0x7f1261b20f40, fname="call_int_int<int>", args=args
entry=0x7f126268a088, nargsf=<optimized out>, nargsf
entry=9223372036854775811, pref=pref
entry=CPyCppyy::Utility::kNone, pcnt=pcnt
entry=0x0) at src/TemplateProxy.cxx:185
#22 0x00007f1260dc0efd in CPyCppyy::tpp_vectorcall (pytmpl=0x7f1261b20f40, args=0x7f126268a088, nargsf=9223372036854775811, kwds=0x0) at /usr/include/c++/12/bits/basic_string.tcc:238
#23 0x0000000000512b50 in _PyObject_VectorcallTstate (kwnames=<optimized out>, nargsf=<optimized out>, args=<optimized out>, callable=<cppyy.TemplateProxy at remote 0x7f1261b20f40>, tstate=0xa890d8 <_PyRuntime+166328>) at ../Include/internal/pycore_call.h:92
#24 PyObject_Vectorcall (callable=<cppyy.TemplateProxy at remote 0x7f1261b20f40>, args=<optimized out>, nargsf=<optimized out>, kwnames=<optimized out>) at ../Objects/call.c:299

Line 19 seems weird. Tmpl_name="<" ?

#19 AddTypeName (tmpl_name="<", tn=<optimized out>, arg=<optimized out>, pref=pref
entry=CPyCppyy::Utility::kNone, pcnt=pcnt
entry=0x0) at src/Utility.cxx:509

Currently using:

cppyy==3.0.0
cppyy-backend==1.14.11
cppyy-cling==6.28.0
CPyCppyy==1.12.13
gcc 12.2.0
Ubuntu 23.04

@wlav
Copy link
Owner

wlav commented Jul 20, 2023

Nice, a fully reproducible crash. :) Thanks! Fixed in repo. (Problem wasn't that traceback line 19, but the code assuming a string type while it had class int.)

@Gabrielcarvfer
Copy link

Now I'm getting a different error. Shouldn't the Python int have been converted to C++ int before getting to the following prototype? Not sure when do these conversions happen, so I'm guessing.

func.prototype.file:1:1: error: expected a type
<class 'int'> (*)(<class 'int'>, <class 'int'>),int,int
^
...
TClass::GetClass: Header Parsing - The representation of int(*)(int,int) was not found in the type system. A lookup in the interpreter is about to be tried: this can cause parsing. This can be avoided selecting int(*)(int,int) in the linkdef/selection file.
cling JIT session error: Failed to materialize symbols: { (main, { _ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPKcEEvT_S8_St20forward_iterator_tag }) }
cling JIT session error: Failed to materialize symbols: { (main, { _ZN16__cppyy_internal10fptr_wrap3Eii }) }
Traceback (most recent call last):
  File "/home/gabriel/./Desktop/cpycppyy/test.py", line 21, in <module>
    print(call_int_int[int](add, 3, 7)) # errors out, trace below
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: Could not find "call_int_int<int>" (set cppyy.set_debug() for C++ errors):
  int ::call_int_int(int(*)(int,int) f, int i1, int i2) =>
    TypeError: could not convert argument 1
  none of the 2 overloaded methods succeeded. Full details:
  int ::call_int_int(int(*)(int,int) f, int i1, int i2) =>
    TypeError: could not convert argument 1
  int ::call_int_int(int(*)(int,int) f, int i1, int i2) =>
    TypeError: could not convert argument 1

@wlav
Copy link
Owner

wlav commented Jul 20, 2023

Interesting, as I didn't (and don't) get that result. However, I can see how that could happen. Presumed fix is in repo.

@Gabrielcarvfer
Copy link

Prototype error went away, but the TypeErrors persist.

@wlav
Copy link
Owner

wlav commented Jul 20, 2023

Right, because of cling JIT session error: Failed to materialize symbols, which I can't reproduce. :(

@Gabrielcarvfer
Copy link

Gabrielcarvfer commented Jul 20, 2023

Hmm. Testing a bit more, found something that may be of interest.

Running the same example:

10
cling JIT session error: Failed to materialize symbols: { (main, { _ZN16__cppyy_internal10fptr_wrap1Eii }) }
cling JIT session error: Failed to materialize symbols: { (main, { _ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPKcEEvT_S8_St20forward_iterator_tag }) }
cling JIT session error: Failed to materialize symbols: { (main, { _ZN16__cppyy_internal10fptr_wrap2Eii }) }
cling JIT session error: Failed to materialize symbols: { (main, { _ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPKcEEvT_S8_St20forward_iterator_tag }) }
cling JIT session error: Failed to materialize symbols: { (main, { _ZN16__cppyy_internal10fptr_wrap3Eii }) }
Traceback (most recent call last):
  File "/home/gabriel/./Desktop/cpycppyy/test.py", line 66, in <module>
    print(call_int_int[int](add, 3, 7)) # errors out, trace below
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...

Tried getting the generated code for that function wrapper that failed to be materialized.

Generated code
namespace __cppyy_internal {
  int fptr_wrap1(int arg0, int arg1) {
    CPYCPPYY_STATIC std::unique_ptr<CPyCppyy::Converter, std::function<void(CPyCppyy::Converter*)>> retconv{CPyCppyy::CreateConverter("int"), CPyCppyy::DestroyConverter};
    CPYCPPYY_STATIC std::vector<std::unique_ptr<CPyCppyy::Converter, std::function<void(CPyCppyy::Converter*)>>> argcvs;
    if (argcvs.empty()) {
      argcvs.reserve(2);
      argcvs.emplace_back(CPyCppyy::CreateConverter("int"), CPyCppyy::DestroyConverter);
      argcvs.emplace_back(CPyCppyy::CreateConverter("int"), CPyCppyy::DestroyConverter);
    }
    int ret{};
    PyGILState_STATE state = PyGILState_Ensure();
    std::vector<PyObject*> pyargs;
    pyargs.reserve(2);
    try {
      pyargs.emplace_back(argcvs[0]->FromMemory((void*)&arg0));
      if (!pyargs.back()) throw 0;
      pyargs.emplace_back(argcvs[1]->FromMemory((void*)&arg1));
      if (!pyargs.back()) throw 1;
    } catch(int) {
      for (auto pyarg : pyargs) Py_XDECREF(pyarg);
      CPyCppyy::PyException pyexc; PyGILState_Release(state); throw pyexc;
    }
    PyObject** ref = (PyObject**)71377200;
    PyObject* pyresult = nullptr;
    if (*ref) pyresult = PyObject_CallFunctionObjArgs(*ref, pyargs[0], pyargs[1], NULL);
    else PyErr_SetString(PyExc_TypeError, "callable was deleted");
    for (auto pyarg : pyargs) Py_DECREF(pyarg);
    bool cOk = (bool)pyresult;
    if (pyresult) {
        cOk = retconv->ToMemory(pyresult, (void*)&ret);
        Py_DECREF(pyresult);
    }
    if (!cOk) { CPyCppyy::PyException pyexc; PyGILState_Release(state); throw pyexc; }
    PyGILState_Release(state);
    return ret;
  }
}

Then defined that manually.

Python code
cppyy.add_include_path("/home/gabriel/Desktop/venv/include/site/python3.11/CPyCppyy/")
cppyy.cppdef("""
#include <API.h>
#include <PyException.h>
namespace __cppyy_internal {
  int fptr_wrap99999(int arg0, int arg1) {
    CPYCPPYY_STATIC std::unique_ptr<CPyCppyy::Converter, std::function<void(CPyCppyy::Converter*)>> retconv{CPyCppyy::CreateConverter("int"), CPyCppyy::DestroyConverter};
    CPYCPPYY_STATIC std::vector<std::unique_ptr<CPyCppyy::Converter, std::function<void(CPyCppyy::Converter*)>>> argcvs;
    if (argcvs.empty()) {
      argcvs.reserve(2);
      argcvs.emplace_back(CPyCppyy::CreateConverter("int"), CPyCppyy::DestroyConverter);
      argcvs.emplace_back(CPyCppyy::CreateConverter("int"), CPyCppyy::DestroyConverter);
    }
    int ret{};
    PyGILState_STATE state = PyGILState_Ensure();
    std::vector<PyObject*> pyargs;
    pyargs.reserve(2);
    try {
      pyargs.emplace_back(argcvs[0]->FromMemory((void*)&arg0));
      if (!pyargs.back()) throw 0;
      pyargs.emplace_back(argcvs[1]->FromMemory((void*)&arg1));
      if (!pyargs.back()) throw 1;
    } catch(int) {
      for (auto pyarg : pyargs) Py_XDECREF(pyarg);
      CPyCppyy::PyException pyexc; PyGILState_Release(state); throw pyexc;
    }
    PyObject** ref = (PyObject**)71377200;
    PyObject* pyresult = nullptr;
    if (*ref) pyresult = PyObject_CallFunctionObjArgs(*ref, pyargs[0], pyargs[1], NULL);
    else PyErr_SetString(PyExc_TypeError, "callable was deleted");
    for (auto pyarg : pyargs) Py_DECREF(pyarg);
    bool cOk = (bool)pyresult;
    if (pyresult) {
        cOk = retconv->ToMemory(pyresult, (void*)&ret);
        Py_DECREF(pyresult);
    }
    if (!cOk) { CPyCppyy::PyException pyexc; PyGILState_Release(state); throw pyexc; }
    PyGILState_Release(state);
    return ret;
  }
}

""")

It still fails the exact same way (expected), but the symbol materialization failure list is different.
When it is defined in the same cppdef as the sumc function, the list includes the sumc function.

cling JIT session error: Failed to materialize symbols: { (main, { _Z4sumcii }) }
cling JIT session error: Failed to materialize symbols: { (main, { _ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPKcEEvT_S8_St20forward_iterator_tag }) }
cling JIT session error: Failed to materialize symbols: { (main, { _ZN16__cppyy_internal10fptr_wrap1Eii }) }

When it is on a different cppdef call, it prints the original list.

@Gabrielcarvfer
Copy link

Gabrielcarvfer commented Jul 24, 2023

Thought it would be nice to call the wrapper function directly and got the following.

IncrementalExecutor::executeFunction: symbol '_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE17_M_use_local_dataEv' unresolved while linking symbol '__cf_4'!
You are probably missing the definition of std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_use_local_data()
Maybe you need to load the corresponding shared library?
Traceback (most recent call last):
  File "/home/gabriel/./Desktop/test.py", line 67, in <module>
    print(__cppyy_internal.fptr_wrap99999( 3, 7))
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
cppyy.gbl.std.runtime_error: int __cppyy_internal::fptr_wrap99999(int arg0, int arg1) =>
    runtime_error: failed to resolve function

GLIBCXX_USE_CXX11_ABI shenanigans?

@N-Coder
Copy link

N-Coder commented Sep 13, 2023

I can reproduce this to differing extents in ubuntu and fedora docker containers. The ubuntu one is set up as follows:

# docker run  -t -i --rm ubuntu bash
apt-get update && apt-get install -y python3 python3-pip python3-dev build-essential wget
python3 -V
pip3 -V
pip3 install cppyy

Now, running the examples from above and my Observer code from #189 works without warnings, but loading ogdf-python yields a similar problem:

# pip3 install ogdf-python ogdf-wheel
# python3 -c "import ogdf_python"
[runStaticInitializersOnce]: Failed to materialize symbols: { (main, { __orc_init_func.cling-module-142, _ZN4ogdfL17s_ogdfInitializerE, _GLOBAL__sub_I_cling_module_142, $.cling-module-142.__inits.0, __cxx_global_var_initcling_module_142_ }) }
[runStaticInitializersOnce]: Failed to materialize symbols: { (main, { __orc_init_func.cling-module-142 }) }

On fedora the issue is easier to reproduce

# docker run  -t -i --rm fedora bash
sudo dnf install -y python3 python3-pip python3-devel gcc g++ cmake wget
python3 -V
pip3 -V
pip3 install cppyy
mv /usr/local/lib64/python3.11/site-packages/cppyy_backend/lib/libcppyy_backend.so /usr/local/lib/python3.11/site-packages/cppyy_backend/lib/libcppyy_backend.so # fix #191
python3 -c "import cppyy" # works

The example from above here yields:

>>> call_int_int(add, 3, 7)
cling JIT session error: Failed to materialize symbols: { (main, { _ZN16__cppyy_internal10fptr_wrap1Eii }) }
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: int ::call_int_int(int(*)(int,int) f, int i1, int i2) =>
    TypeError: could not convert argument 1

Running my Observer code:

# wget https://gist.githubusercontent.com/N-Coder/c1fafdd5ff2aae1a134852416e9e3587/raw/f7189e70f5df36cba36cfc6da36332c965ddc125/test.cpp
# python3
Python 3.11.5 (main, Aug 28 2023, 00:00:00) [GCC 13.2.1 20230728 (Red Hat 13.2.1-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from cppyy import *
>>> import cppyy.gbl as c
>>> 
>>> include("test.cpp")
[runStaticInitializersOnce]: Failed to materialize symbols: { (main, { $.cling-module-142.__inits.0, _ZN10MyObserverD1Ev, _ZN10MyObserverD0Ev, _ZTV10MyObserver, _ZN8Observer7observeEP10Observable, _ZN10MyObserver12onRegisteredEP10Observable, _ZTI10MyObserver, long_lived_obs, _ZN8ObserverD1Ev, _ZN8Observer12onRegisteredEP10Observable, __orc_init_func.cling-module-142, _ZNSt7__cxx114listIP8ObserverSaIS2_EED1Ev, _GLOBAL__sub_I_cling_module_142, _ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPKcEEvT_S8_St20forward_iterator_tag, _ZTS10MyObserver, _ZN10MyObserverD2Ev, _ZTI8Observer, _ZTS8Observer, _ZTV8Observer, main, _ZN10MyObserverC2Ev, _ZN8ObserverD2Ev, _ZN8ObserverD0Ev, __cxx_global_var_initcling_module_142_, _ZN10MyObserver11onThingDoneERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE, __clang_call_terminate }) }
True
>>> 
>>> class MyObserver(c.Observer):
...     def onThingDone(self, msg):
...         print(id(self), "onThingDone", msg)
...     def onRegistered(self, prev):
...         print(id(self), "onRegistered", "was", prev, "is", self.observed)
... 
>>> obj = c.Observable()
[runStaticInitializersOnce]: Failed to materialize symbols: { (main, { __orc_init_func.cling-module-142 }) }
>>> obs = MyObserver()
cling JIT session error: Failed to materialize symbols: { (main, { _ZN8Observer7observeEP10Observable }) }
cling JIT session error: Failed to materialize symbols: { (main, { _ZTVN16__cppyy_internal11Dispatcher1E }) }
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: none of the 2 overloaded methods succeeded. Full details:
  none of the 3 overloaded methods succeeded. Full details:
  Dispatcher1::Dispatcher1(const __cppyy_internal::Dispatcher1& other) =>
    TypeError: takes at least 1 arguments (0 given)
  Dispatcher1::Dispatcher1(const Observer& a0) =>
    TypeError: takes at least 1 arguments (0 given)
  __cppyy_internal::Dispatcher1 constructor failed
  none of the 3 overloaded methods succeeded. Full details:
  Dispatcher1::Dispatcher1(const __cppyy_internal::Dispatcher1& other) =>
    TypeError: takes at least 1 arguments (0 given)
  Dispatcher1::Dispatcher1(const Observer& a0) =>
    TypeError: takes at least 1 arguments (0 given)
  __cppyy_internal::Dispatcher1 constructor failed
>>> exit()
cling JIT session error: Failed to materialize symbols: { (main, { _ZN8Observer7observeEP10Observable }) }

And loading ogdf-python:

# python3 -c "import ogdf_python"
[runStaticInitializersOnce]: Failed to materialize symbols: { (main, { __cxx_global_var_initcling_module_146_, _GLOBAL__sub_I_cling_module_146, __orc_init_func.cling-module-146, _ZN4ogdfL17s_ogdfInitializerE, $.cling-module-146.__inits.0 }) }
[runStaticInitializersOnce]: Failed to materialize symbols: { (main, { __orc_init_func.cling-module-146 }) }

@N-Coder
Copy link

N-Coder commented Oct 9, 2023

It seems that some fedora update now broke cppyy version 2.4, so now downgrading is also no longer an option and I currently cannot install a working cppyy version (2.4 due to below error, 3.0 due to the "Failed to materialize symbols" problems).

# docker run  -t -i --rm fedora bash
sudo dnf update -y
sudo dnf install -y python3 python3-pip python3-devel gcc g++ cmake wget
pip3 install "cppyy<3"
mv /usr/local/lib64/python3.11/site-packages/cppyy_backend/lib/libcppyy_backend.so /usr/local/lib/python3.11/site-packages/cppyy_backend/lib/libcppyy_backend.so # fix #191
python3 -c "import cppyy"
Output
(Re-)building pre-compiled headers (options: -O2 -march=native); this may take a minute ...
In file included from input_line_10:9:
In file included from ./etc/dictpch/allHeaders.h:257:
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/charconv:245:16: error: variables defined in a constexpr function must be initialized
      unsigned __len;
               ^
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/charconv:358:9: error: no matching function for call to '__to_chars_8'
        return __detail::__to_chars_8(__first, __last, __unsigned_val);
               ^~~~~~~~~~~~~~~~~~~~~~
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/charconv:370:1: note: in instantiation of function template specialization 'std::__to_chars_i<char>' requested here
_GLIBCXX_TO_CHARS(char)
^
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/charconv:369:17: note: expanded from macro '_GLIBCXX_TO_CHARS'
  { return std::__to_chars_i<T>(__first, __last, __value, __base); }
                ^
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/charconv:240:5: note: candidate template ignored: substitution failure [with _Tp = unsigned int]
    __to_chars_8(char* __first, char* __last, _Tp __val) noexcept
    ^
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/charconv:358:9: error: no matching function for call to '__to_chars_8'
        return __detail::__to_chars_8(__first, __last, __unsigned_val);
               ^~~~~~~~~~~~~~~~~~~~~~
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/charconv:371:1: note: in instantiation of function template specialization 'std::__to_chars_i<signed char>' requested here
_GLIBCXX_TO_CHARS(signed char)
^
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/charconv:369:17: note: expanded from macro '_GLIBCXX_TO_CHARS'
  { return std::__to_chars_i<T>(__first, __last, __value, __base); }
                ^
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/charconv:240:5: note: candidate template ignored: substitution failure [with _Tp = unsigned int]
    __to_chars_8(char* __first, char* __last, _Tp __val) noexcept
    ^
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/charconv:358:9: error: no matching function for call to '__to_chars_8'
        return __detail::__to_chars_8(__first, __last, __unsigned_val);
               ^~~~~~~~~~~~~~~~~~~~~~
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/charconv:372:1: note: in instantiation of function template specialization 'std::__to_chars_i<unsigned char>' requested here
_GLIBCXX_TO_CHARS(unsigned char)
^
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/charconv:369:17: note: expanded from macro '_GLIBCXX_TO_CHARS'
  { return std::__to_chars_i<T>(__first, __last, __value, __base); }
                ^
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/charconv:240:5: note: candidate template ignored: substitution failure [with _Tp = unsigned int]
    __to_chars_8(char* __first, char* __last, _Tp __val) noexcept
    ^
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/charconv:358:9: error: no matching function for call to '__to_chars_8'
        return __detail::__to_chars_8(__first, __last, __unsigned_val);
               ^~~~~~~~~~~~~~~~~~~~~~
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/charconv:373:1: note: in instantiation of function template specialization 'std::__to_chars_i<short>' requested here
_GLIBCXX_TO_CHARS(signed short)
^
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/charconv:369:17: note: expanded from macro '_GLIBCXX_TO_CHARS'
  { return std::__to_chars_i<T>(__first, __last, __value, __base); }
                ^
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/charconv:240:5: note: candidate template ignored: substitution failure [with _Tp = unsigned int]
    __to_chars_8(char* __first, char* __last, _Tp __val) noexcept
    ^
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/charconv:358:9: error: no matching function for call to '__to_chars_8'
        return __detail::__to_chars_8(__first, __last, __unsigned_val);
               ^~~~~~~~~~~~~~~~~~~~~~
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/charconv:374:1: note: in instantiation of function template specialization 'std::__to_chars_i<unsigned short>' requested here
_GLIBCXX_TO_CHARS(unsigned short)
^
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/charconv:369:17: note: expanded from macro '_GLIBCXX_TO_CHARS'
  { return std::__to_chars_i<T>(__first, __last, __value, __base); }
                ^
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/charconv:240:5: note: candidate template ignored: substitution failure [with _Tp = unsigned int]
    __to_chars_8(char* __first, char* __last, _Tp __val) noexcept
    ^
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/charconv:358:9: error: no matching function for call to '__to_chars_8'
        return __detail::__to_chars_8(__first, __last, __unsigned_val);
               ^~~~~~~~~~~~~~~~~~~~~~
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/charconv:375:1: note: in instantiation of function template specialization 'std::__to_chars_i<int>' requested here
_GLIBCXX_TO_CHARS(signed int)
^
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/charconv:369:17: note: expanded from macro '_GLIBCXX_TO_CHARS'
  { return std::__to_chars_i<T>(__first, __last, __value, __base); }
                ^
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/charconv:240:5: note: candidate template ignored: substitution failure [with _Tp = unsigned int]
    __to_chars_8(char* __first, char* __last, _Tp __val) noexcept
    ^
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/charconv:358:9: error: no matching function for call to '__to_chars_8'
        return __detail::__to_chars_8(__first, __last, __unsigned_val);
               ^~~~~~~~~~~~~~~~~~~~~~
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/charconv:376:1: note: in instantiation of function template specialization 'std::__to_chars_i<unsigned int>' requested here
_GLIBCXX_TO_CHARS(unsigned int)
^
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/charconv:369:17: note: expanded from macro '_GLIBCXX_TO_CHARS'
  { return std::__to_chars_i<T>(__first, __last, __value, __base); }
                ^
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/charconv:240:5: note: candidate template ignored: substitution failure [with _Tp = unsigned int]
    __to_chars_8(char* __first, char* __last, _Tp __val) noexcept
    ^
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/charconv:358:9: error: no matching function for call to '__to_chars_8'
        return __detail::__to_chars_8(__first, __last, __unsigned_val);
               ^~~~~~~~~~~~~~~~~~~~~~
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/charconv:377:1: note: in instantiation of function template specialization 'std::__to_chars_i<long>' requested here
_GLIBCXX_TO_CHARS(signed long)
^
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/charconv:369:17: note: expanded from macro '_GLIBCXX_TO_CHARS'
  { return std::__to_chars_i<T>(__first, __last, __value, __base); }
                ^
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/charconv:240:5: note: candidate template ignored: substitution failure [with _Tp = unsigned long]
    __to_chars_8(char* __first, char* __last, _Tp __val) noexcept
    ^
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/charconv:358:9: error: no matching function for call to '__to_chars_8'
        return __detail::__to_chars_8(__first, __last, __unsigned_val);
               ^~~~~~~~~~~~~~~~~~~~~~
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/charconv:378:1: note: in instantiation of function template specialization 'std::__to_chars_i<unsigned long>' requested here
_GLIBCXX_TO_CHARS(unsigned long)
^
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/charconv:369:17: note: expanded from macro '_GLIBCXX_TO_CHARS'
  { return std::__to_chars_i<T>(__first, __last, __value, __base); }
                ^
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/charconv:240:5: note: candidate template ignored: substitution failure [with _Tp = unsigned long]
    __to_chars_8(char* __first, char* __last, _Tp __val) noexcept
    ^
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/charconv:358:9: error: no matching function for call to '__to_chars_8'
        return __detail::__to_chars_8(__first, __last, __unsigned_val);
               ^~~~~~~~~~~~~~~~~~~~~~
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/charconv:379:1: note: in instantiation of function template specialization 'std::__to_chars_i<long long>' requested here
_GLIBCXX_TO_CHARS(signed long long)
^
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/charconv:369:17: note: expanded from macro '_GLIBCXX_TO_CHARS'
  { return std::__to_chars_i<T>(__first, __last, __value, __base); }
                ^
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/charconv:240:5: note: candidate template ignored: substitution failure [with _Tp = unsigned long]
    __to_chars_8(char* __first, char* __last, _Tp __val) noexcept
    ^
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/charconv:358:9: error: no matching function for call to '__to_chars_8'
        return __detail::__to_chars_8(__first, __last, __unsigned_val);
               ^~~~~~~~~~~~~~~~~~~~~~
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/charconv:380:1: note: in instantiation of function template specialization 'std::__to_chars_i<unsigned long long>' requested here
_GLIBCXX_TO_CHARS(unsigned long long)
^
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/charconv:369:17: note: expanded from macro '_GLIBCXX_TO_CHARS'
  { return std::__to_chars_i<T>(__first, __last, __value, __base); }
                ^
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/charconv:240:5: note: candidate template ignored: substitution failure [with _Tp = unsigned long]
    __to_chars_8(char* __first, char* __last, _Tp __val) noexcept
    ^
Error: ./bin/rootcling: compilation failure (/tmp/allDict99f34a9f1b_dictUmbrella.h)
/usr/local/lib/python3.11/site-packages/cppyy_backend/loader.py:139: UserWarning: No precompiled header available (failed to build); this may impact performance.
  warnings.warn('No precompiled header available (%s); this may impact performance.' % msg)
In file included from libCoreLegacy dictionary payload:7:
In file included from /usr/local/lib/python3.11/site-packages/cppyy_backend/include/Riostream.h:24:
In file included from /usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/fstream:42:
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/codecvt.h:344:20: error: explicit specialization of undeclared template class 'messages'
      friend class messages<char>;
                   ^       ~~~~~~
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/codecvt.h:407:20: error: explicit specialization of undeclared template class 'messages'
      friend class messages<wchar_t>;
                   ^       ~~~~~~~~~
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/codecvt.h:717:28: error: no member named 'c_str' in 'std::__cxx11::basic_string<char>'
      : codecvt_byname(__s.c_str(), __refs) { }
                       ~~~ ^
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/codecvt.h:737:28: error: no member named 'c_str' in 'std::__cxx11::basic_string<char>'
      : codecvt_byname(__s.c_str(), __refs) { }
                       ~~~ ^
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/codecvt.h:755:28: error: no member named 'c_str' in 'std::__cxx11::basic_string<char>'
      : codecvt_byname(__s.c_str(), __refs) { }
                       ~~~ ^
In file included from libCoreLegacy dictionary payload:7:
In file included from /usr/local/lib/python3.11/site-packages/cppyy_backend/include/Riostream.h:24:
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/fstream:339:25: error: no member named 'c_str' in 'std::__cxx11::basic_string<char>'
      { return open(__s.c_str(), __mode); }
                    ~~~ ^
In file included from libCoreLegacy dictionary payload:7:
In file included from /usr/local/lib/python3.11/site-packages/cppyy_backend/include/Riostream.h:26:
In file included from /usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/iomanip:45:
In file included from /usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/locale:43:
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/locale_facets_nonio.h:812:29: error: no member named 'c_str' in 'std::__cxx11::basic_string<char>'
      : time_get_byname(__s.c_str(), __refs) { }
                        ~~~ ^
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/locale_facets_nonio.h:946:29: error: no member named 'c_str' in 'std::__cxx11::basic_string<char>'
      : time_put_byname(__s.c_str(), __refs) { }
                        ~~~ ^
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/locale_facets_nonio.h:1477:31: error: no member named 'c_str' in 'std::__cxx11::basic_string<char>'
      : moneypunct_byname(__s.c_str(), __refs) { }
                          ~~~ ^
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/locale_facets_nonio.h:2049:29: error: no member named 'c_str' in 'std::__cxx11::basic_string<char>'
      : messages_byname(__s.c_str(), __refs) { }
                        ~~~ ^
In file included from libCoreLegacy dictionary payload:7:
In file included from /usr/local/lib/python3.11/site-packages/cppyy_backend/include/Riostream.h:26:
In file included from /usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/iomanip:45:
In file included from /usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/locale:43:
In file included from /usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/locale_facets_nonio.h:2064:
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/x86_64-redhat-linux/bits/messages_members.h:73:26: error: no member named 'c_str' in 'std::__cxx11::basic_string<char>'
      bindtextdomain(__s.c_str(), __dir);
                     ~~~ ^
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/x86_64-redhat-linux/bits/messages_members.h:93:22: error: no member named 'c_str' in 'std::__cxx11::basic_string<char>'
      textdomain(__s.c_str());
                 ~~~ ^
In file included from libCoreLegacy dictionary payload:7:
In file included from /usr/local/lib/python3.11/site-packages/cppyy_backend/include/Riostream.h:26:
In file included from /usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/iomanip:45:
In file included from /usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/locale:43:
In file included from /usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/locale_facets_nonio.h:2069:
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/locale_facets_nonio.tcc:100:35: error: no member named 'size' in 'std::__cxx11::basic_string<char>'
      const size_t __g_size = __g.size();
                              ~~~ ^
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/locale_facets_nonio.tcc:160:9: error: no matching constructor for initialization of 'std::string' (aka 'basic_string<char>')
        string __grouping_tmp;
               ^
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/basic_string.h:748:9: note: candidate constructor template not viable: requires at least 2 arguments, but 0 were provided
        basic_string(_InputIterator __beg, _InputIterator __end,
        ^
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/basic_string.h:525:7: note: candidate constructor not viable: requires single argument '__a', but no arguments were provided
      basic_string(const _Alloc& __a) _GLIBCXX_NOEXCEPT
      ^
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/basic_string.h:695:7: note: candidate constructor not viable: requires at least argument '__l', but no arguments were provided
      basic_string(initializer_list<_CharT> __l, const _Alloc& __a = _Alloc())
      ^
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/basic_string.h:700:7: note: candidate constructor not viable: requires 2 arguments, but 0 were provided
      basic_string(const basic_string& __str, const _Alloc& __a)
      ^
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/basic_string.h:705:7: note: candidate constructor not viable: requires 2 arguments, but 0 were provided
      basic_string(basic_string&& __str, const _Alloc& __a)
      ^
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/basic_string.h:554:7: note: candidate constructor not viable: requires at least 2 arguments, but 0 were provided
      basic_string(const basic_string& __str, size_type __pos,
      ^
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/basic_string.h:571:7: note: candidate constructor not viable: requires 3 arguments, but 0 were provided
      basic_string(const basic_string& __str, size_type __pos,
      ^
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/basic_string.h:654:7: note: candidate constructor not viable: requires at least 2 arguments, but 0 were provided
      basic_string(size_type __n, _CharT __c, const _Alloc& __a = _Alloc())
      ^
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/basic_string.h:589:7: note: candidate constructor not viable: requires 4 arguments, but 0 were provided
      basic_string(const basic_string& __str, size_type __pos,
      ^
In file included from libCoreLegacy dictionary payload:7:
In file included from /usr/local/lib/python3.11/site-packages/cppyy_backend/include/Riostream.h:26:
In file included from /usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/iomanip:45:
In file included from /usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/locale:43:
In file included from /usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/locale_facets_nonio.h:2069:
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/locale_facets_nonio.tcc:173:9: error: no matching constructor for initialization of 'std::string' (aka 'basic_string<char>')
        string __res;
               ^
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/basic_string.h:748:9: note: candidate constructor template not viable: requires at least 2 arguments, but 0 were provided
        basic_string(_InputIterator __beg, _InputIterator __end,
        ^
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/basic_string.h:525:7: note: candidate constructor not viable: requires single argument '__a', but no arguments were provided
      basic_string(const _Alloc& __a) _GLIBCXX_NOEXCEPT
      ^
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/basic_string.h:695:7: note: candidate constructor not viable: requires at least argument '__l', but no arguments were provided
      basic_string(initializer_list<_CharT> __l, const _Alloc& __a = _Alloc())
      ^
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/basic_string.h:700:7: note: candidate constructor not viable: requires 2 arguments, but 0 were provided
      basic_string(const basic_string& __str, const _Alloc& __a)
      ^
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/basic_string.h:705:7: note: candidate constructor not viable: requires 2 arguments, but 0 were provided
      basic_string(basic_string&& __str, const _Alloc& __a)
      ^
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/basic_string.h:554:7: note: candidate constructor not viable: requires at least 2 arguments, but 0 were provided
      basic_string(const basic_string& __str, size_type __pos,
      ^
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/basic_string.h:571:7: note: candidate constructor not viable: requires 3 arguments, but 0 were provided
      basic_string(const basic_string& __str, size_type __pos,
      ^
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/basic_string.h:654:7: note: candidate constructor not viable: requires at least 2 arguments, but 0 were provided
      basic_string(size_type __n, _CharT __c, const _Alloc& __a = _Alloc())
      ^
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/basic_string.h:589:7: note: candidate constructor not viable: requires 4 arguments, but 0 were provided
      basic_string(const basic_string& __str, size_type __pos,
      ^
In file included from libCoreLegacy dictionary payload:7:
In file included from /usr/local/lib/python3.11/site-packages/cppyy_backend/include/Riostream.h:26:
In file included from /usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/iomanip:45:
In file included from /usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/locale:43:
In file included from /usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/locale_facets_nonio.h:2069:
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/locale_facets_nonio.tcc:374:14: error: no matching constructor for initialization of 'std::string' (aka 'basic_string<char>')
      string __str;
             ^
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/basic_string.h:748:9: note: candidate constructor template not viable: requires at least 2 arguments, but 0 were provided
        basic_string(_InputIterator __beg, _InputIterator __end,
        ^
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/basic_string.h:525:7: note: candidate constructor not viable: requires single argument '__a', but no arguments were provided
      basic_string(const _Alloc& __a) _GLIBCXX_NOEXCEPT
      ^
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/basic_string.h:695:7: note: candidate constructor not viable: requires at least argument '__l', but no arguments were provided
      basic_string(initializer_list<_CharT> __l, const _Alloc& __a = _Alloc())
      ^
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/basic_string.h:700:7: note: candidate constructor not viable: requires 2 arguments, but 0 were provided
      basic_string(const basic_string& __str, const _Alloc& __a)
      ^
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/basic_string.h:705:7: note: candidate constructor not viable: requires 2 arguments, but 0 were provided
      basic_string(basic_string&& __str, const _Alloc& __a)
      ^
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/basic_string.h:554:7: note: candidate constructor not viable: requires at least 2 arguments, but 0 were provided
      basic_string(const basic_string& __str, size_type __pos,
      ^
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/basic_string.h:571:7: note: candidate constructor not viable: requires 3 arguments, but 0 were provided
      basic_string(const basic_string& __str, size_type __pos,
      ^
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/basic_string.h:654:7: note: candidate constructor not viable: requires at least 2 arguments, but 0 were provided
      basic_string(size_type __n, _CharT __c, const _Alloc& __a = _Alloc())
      ^
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/basic_string.h:589:7: note: candidate constructor not viable: requires 4 arguments, but 0 were provided
      basic_string(const basic_string& __str, size_type __pos,
      ^
In file included from libCoreLegacy dictionary payload:7:
In file included from /usr/local/lib/python3.11/site-packages/cppyy_backend/include/Riostream.h:26:
In file included from /usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/iomanip:45:
In file included from /usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/locale:43:
In file included from /usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/locale_facets_nonio.h:2069:
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/locale_facets_nonio.tcc:392:14: error: no matching constructor for initialization of 'std::string' (aka 'basic_string<char>')
      string __str;
             ^
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/basic_string.h:748:9: note: candidate constructor template not viable: requires at least 2 arguments, but 0 were provided
        basic_string(_InputIterator __beg, _InputIterator __end,
        ^
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/basic_string.h:525:7: note: candidate constructor not viable: requires single argument '__a', but no arguments were provided
      basic_string(const _Alloc& __a) _GLIBCXX_NOEXCEPT
      ^
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/basic_string.h:695:7: note: candidate constructor not viable: requires at least argument '__l', but no arguments were provided
      basic_string(initializer_list<_CharT> __l, const _Alloc& __a = _Alloc())
      ^
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/basic_string.h:700:7: note: candidate constructor not viable: requires 2 arguments, but 0 were provided
      basic_string(const basic_string& __str, const _Alloc& __a)
      ^
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/basic_string.h:705:7: note: candidate constructor not viable: requires 2 arguments, but 0 were provided
      basic_string(basic_string&& __str, const _Alloc& __a)
      ^
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/basic_string.h:554:7: note: candidate constructor not viable: requires at least 2 arguments, but 0 were provided
      basic_string(const basic_string& __str, size_type __pos,
      ^
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/basic_string.h:571:7: note: candidate constructor not viable: requires 3 arguments, but 0 were provided
      basic_string(const basic_string& __str, size_type __pos,
      ^
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/basic_string.h:654:7: note: candidate constructor not viable: requires at least 2 arguments, but 0 were provided
      basic_string(size_type __n, _CharT __c, const _Alloc& __a = _Alloc())
      ^
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/basic_string.h:589:7: note: candidate constructor not viable: requires 4 arguments, but 0 were provided
      basic_string(const basic_string& __str, size_type __pos,
      ^
In file included from libCoreLegacy dictionary payload:10:
In file included from /usr/local/lib/python3.11/site-packages/cppyy_backend/include/TBuffer.h:24:
In file included from /usr/local/lib/python3.11/site-packages/cppyy_backend/include/TDataType.h:25:
In file included from /usr/local/lib/python3.11/site-packages/cppyy_backend/include/TDictionary.h:41:
In file included from /usr/local/lib/python3.11/site-packages/cppyy_backend/include/TNamed.h:25:
In file included from /usr/local/lib/python3.11/site-packages/cppyy_backend/include/TString.h:26:
In file included from /usr/local/lib/python3.11/site-packages/cppyy_backend/include/TMathBase.h:32:
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/cmath:89:3: error: redefinition of 'acos'
  acos(float __x)
  ^
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/cmath:89:3: note: previous definition is here
  acos(float __x)
  ^
In file included from libCoreLegacy dictionary payload:10:
In file included from /usr/local/lib/python3.11/site-packages/cppyy_backend/include/TBuffer.h:24:
In file included from /usr/local/lib/python3.11/site-packages/cppyy_backend/include/TDataType.h:25:
In file included from /usr/local/lib/python3.11/site-packages/cppyy_backend/include/TDictionary.h:41:
In file included from /usr/local/lib/python3.11/site-packages/cppyy_backend/include/TNamed.h:25:
In file included from /usr/local/lib/python3.11/site-packages/cppyy_backend/include/TString.h:26:
In file included from /usr/local/lib/python3.11/site-packages/cppyy_backend/include/TMathBase.h:32:
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/cmath:93:3: error: redefinition of 'acos'
  acos(long double __x)
  ^
/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/cmath:93:3: note: previous definition is here
  acos(long double __x)
  ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
 *** Break *** segmentation violation
 Generating stack trace...
sh: line 1: which: command not found
/usr/bin/addr2line: '0x000055dea312b095': No such file
 0x00007f3c9619f6c6 in CPyCppyy::CreateScopeProxy(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, _object*, unsigned int) at /usr/include/c++/13/bits/new_allocator.h:92 from /usr/local/lib64/python3.11/site-packages/libcppyy.cpython-311-x86_64-linux-gnu.so
 0x00007f3c961a09ec in CPyCppyy::CreateScopeProxy(_object*, _object*) at /tmp/pip-install-7e9f1_0m/cpycppyy_ab9751a441be492493765340553da7cf/src/ProxyWrappers.cxx:530 from /usr/local/lib64/python3.11/site-packages/libcppyy.cpython-311-x86_64-linux-gnu.so
 0x00007f3c9bbe2c78 in <unknown> from /lib64/libpython3.11.so.1.0
 0x00007f3c9bbc5d93 in _PyObject_MakeTpCall + 0x73 from /lib64/libpython3.11.so.1.0
 0x00007f3c9bbce7c4 in _PyEval_EvalFrameDefault + 0x8c4 from /lib64/libpython3.11.so.1.0
 0x00007f3c9bbca7da in <unknown> from /lib64/libpython3.11.so.1.0
 0x00007f3c9bc4f6ec in PyEval_EvalCode + 0xac from /lib64/libpython3.11.so.1.0
 0x00007f3c9bc66142 in <unknown> from /lib64/libpython3.11.so.1.0
 0x00007f3c9bbdc06a in <unknown> from /lib64/libpython3.11.so.1.0
 0x00007f3c9bbd25b1 in _PyEval_EvalFrameDefault + 0x46b1 from /lib64/libpython3.11.so.1.0
 0x00007f3c9bbca7da in <unknown> from /lib64/libpython3.11.so.1.0
 0x00007f3c9bbe23e6 in <unknown> from /lib64/libpython3.11.so.1.0
 0x00007f3c9bc06094 in PyObject_CallMethodObjArgs + 0x124 from /lib64/libpython3.11.so.1.0
 0x00007f3c9bc04794 in PyImport_ImportModuleLevelObject + 0x3f4 from /lib64/libpython3.11.so.1.0
 0x00007f3c9bbd4aa0 in _PyEval_EvalFrameDefault + 0x6ba0 from /lib64/libpython3.11.so.1.0
 0x00007f3c9bbca7da in <unknown> from /lib64/libpython3.11.so.1.0
 0x00007f3c9bc4f6ec in PyEval_EvalCode + 0xac from /lib64/libpython3.11.so.1.0
 0x00007f3c9bc66142 in <unknown> from /lib64/libpython3.11.so.1.0
 0x00007f3c9bbdc06a in <unknown> from /lib64/libpython3.11.so.1.0
 0x00007f3c9bbd25b1 in _PyEval_EvalFrameDefault + 0x46b1 from /lib64/libpython3.11.so.1.0
 0x00007f3c9bbca7da in <unknown> from /lib64/libpython3.11.so.1.0
 0x00007f3c9bbe23e6 in <unknown> from /lib64/libpython3.11.so.1.0
 0x00007f3c9bc06094 in PyObject_CallMethodObjArgs + 0x124 from /lib64/libpython3.11.so.1.0
 0x00007f3c9bc04794 in PyImport_ImportModuleLevelObject + 0x3f4 from /lib64/libpython3.11.so.1.0
 0x00007f3c9bbd4aa0 in _PyEval_EvalFrameDefault + 0x6ba0 from /lib64/libpython3.11.so.1.0
 0x00007f3c9bbca7da in <unknown> from /lib64/libpython3.11.so.1.0
 0x00007f3c9bc4f6ec in PyEval_EvalCode + 0xac from /lib64/libpython3.11.so.1.0
 0x00007f3c9bc6cc33 in <unknown> from /lib64/libpython3.11.so.1.0
 0x00007f3c9bc692fa in <unknown> from /lib64/libpython3.11.so.1.0
 0x00007f3c9bc5dfdd in PyRun_StringFlags + 0x6d from /lib64/libpython3.11.so.1.0
 0x00007f3c9bc5dd20 in PyRun_SimpleStringFlags + 0x40 from /lib64/libpython3.11.so.1.0
 0x00007f3c9bc7842e in Py_RunMain + 0x3ae from /lib64/libpython3.11.so.1.0
 0x00007f3c9bc3f9fb in Py_BytesMain + 0x3b from /lib64/libpython3.11.so.1.0
 0x00007f3c9b85eb8a in <unknown> from /lib64/libc.so.6
 0x00007f3c9b85ec4b in __libc_start_main at :? from /lib64/libc.so.6
 0x000055dea312b095 in _start + 0x25 from python3
 *** Break *** segmentation violation
 Generating stack trace...
sh: line 1: which: command not found
/usr/bin/addr2line: '0x000055dea312b095': No such file
 0x00007f3c9619f6c6 in CPyCppyy::CreateScopeProxy(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, _object*, unsigned int) at /usr/include/c++/13/bits/new_allocator.h:92 from /usr/local/lib64/python3.11/site-packages/libcppyy.cpython-311-x86_64-linux-gnu.so
 0x00007f3c961a09ec in CPyCppyy::CreateScopeProxy(_object*, _object*) at /tmp/pip-install-7e9f1_0m/cpycppyy_ab9751a441be492493765340553da7cf/src/ProxyWrappers.cxx:530 from /usr/local/lib64/python3.11/site-packages/libcppyy.cpython-311-x86_64-linux-gnu.so
 0x00007f3c9bbe2c78 in <unknown> from /lib64/libpython3.11.so.1.0
 0x00007f3c9bbc5d93 in _PyObject_MakeTpCall + 0x73 from /lib64/libpython3.11.so.1.0
 0x00007f3c9bbce7c4 in _PyEval_EvalFrameDefault + 0x8c4 from /lib64/libpython3.11.so.1.0
 0x00007f3c9bbca7da in <unknown> from /lib64/libpython3.11.so.1.0
 0x00007f3c9bc4f6ec in PyEval_EvalCode + 0xac from /lib64/libpython3.11.so.1.0
 0x00007f3c9bc66142 in <unknown> from /lib64/libpython3.11.so.1.0
 0x00007f3c9bbdc06a in <unknown> from /lib64/libpython3.11.so.1.0
 0x00007f3c9bbd25b1 in _PyEval_EvalFrameDefault + 0x46b1 from /lib64/libpython3.11.so.1.0
 0x00007f3c9bbca7da in <unknown> from /lib64/libpython3.11.so.1.0
 0x00007f3c9bbe23e6 in <unknown> from /lib64/libpython3.11.so.1.0
 0x00007f3c9bc06094 in PyObject_CallMethodObjArgs + 0x124 from /lib64/libpython3.11.so.1.0
 0x00007f3c9bc04794 in PyImport_ImportModuleLevelObject + 0x3f4 from /lib64/libpython3.11.so.1.0
 0x00007f3c9bbd4aa0 in _PyEval_EvalFrameDefault + 0x6ba0 from /lib64/libpython3.11.so.1.0
 0x00007f3c9bbca7da in <unknown> from /lib64/libpython3.11.so.1.0
 0x00007f3c9bc4f6ec in PyEval_EvalCode + 0xac from /lib64/libpython3.11.so.1.0
 0x00007f3c9bc66142 in <unknown> from /lib64/libpython3.11.so.1.0
 0x00007f3c9bbdc06a in <unknown> from /lib64/libpython3.11.so.1.0
 0x00007f3c9bbd25b1 in _PyEval_EvalFrameDefault + 0x46b1 from /lib64/libpython3.11.so.1.0
 0x00007f3c9bbca7da in <unknown> from /lib64/libpython3.11.so.1.0
 0x00007f3c9bbe23e6 in <unknown> from /lib64/libpython3.11.so.1.0
 0x00007f3c9bc06094 in PyObject_CallMethodObjArgs + 0x124 from /lib64/libpython3.11.so.1.0
 0x00007f3c9bc04794 in PyImport_ImportModuleLevelObject + 0x3f4 from /lib64/libpython3.11.so.1.0
 0x00007f3c9bbd4aa0 in _PyEval_EvalFrameDefault + 0x6ba0 from /lib64/libpython3.11.so.1.0
 0x00007f3c9bbca7da in <unknown> from /lib64/libpython3.11.so.1.0
 0x00007f3c9bc4f6ec in PyEval_EvalCode + 0xac from /lib64/libpython3.11.so.1.0
 0x00007f3c9bc6cc33 in <unknown> from /lib64/libpython3.11.so.1.0
 0x00007f3c9bc692fa in <unknown> from /lib64/libpython3.11.so.1.0
 0x00007f3c9bc5dfdd in PyRun_StringFlags + 0x6d from /lib64/libpython3.11.so.1.0
 0x00007f3c9bc5dd20 in PyRun_SimpleStringFlags + 0x40 from /lib64/libpython3.11.so.1.0
 0x00007f3c9bc7842e in Py_RunMain + 0x3ae from /lib64/libpython3.11.so.1.0
 0x00007f3c9bc3f9fb in Py_BytesMain + 0x3b from /lib64/libpython3.11.so.1.0
 0x00007f3c9b85eb8a in <unknown> from /lib64/libc.so.6
 0x00007f3c9b85ec4b in __libc_start_main at :? from /lib64/libc.so.6
 0x000055dea312b095 in _start + 0x25 from python3

There seem to be compile errors due to the "(Re-)building pre-compiled headers" and also some after "No precompiled header available (failed to build)" and lastly everything breaks down with

/usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/cmath:93:3: error: redefinition of 'acos'
[...]
fatal error: too many errors emitted, stopping now [-ferror-limit=]
 *** Break *** segmentation violation
 Generating stack trace...
sh: line 1: which: command not found
/usr/bin/addr2line: '0x000055dea312b095': No such file
 0x00007f3c9619f6c6 in CPyCppyy::CreateScopeProxy(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, _object*, unsigned int) at /usr/include/c++/13/bits/new_allocator.h:92 from /usr/local/lib64/python3.11/site-packages/libcppyy.cpython-311-x86_64-linux-gnu.so

@Gabrielcarvfer
Copy link

Gabrielcarvfer commented Oct 19, 2023

@wlav found a workaround in https://github.com/sxs-collaboration/spectre/pull/5222/files#diff-093aadf224e5fee0d33ae1810f2f1c23304fb5ca398ba6b96c4e7918e0811729

It is apparently a bug caused by the PCH (I've been hitting a few with C++20, so I'm not surprised).

import cppyy
cppyy.cppdef("""
template std::__cxx11::basic_string<char, 
              std::char_traits<char>,
              std::allocator<char>>::pointer std::__cxx11::basic_string<char, std::char_traits<char>,
              std::allocator<char>>::_M_use_local_data();
template std::__cxx11::basic_string<wchar_t, 
             std::char_traits<wchar_t>,
             std::allocator<wchar_t>>::pointer std::__cxx11::basic_string<wchar_t, 
             std::char_traits<wchar_t>,
             std::allocator<wchar_t>>::_M_use_local_data();
                           
template<typename T>
T call_int_int_temp(T (*f)(T,T), T i1, T i2) {
    return f(i1, i2);
}
int sumc(int a, int b)
{
    return a+b;    
}
""")

from cppyy.gbl import call_int_int_temp, sumc

def add(a: int, b: int)->int:
    return a + b

print(call_int_int_temp[int](sumc, 3, 7)) # prints 10 as expected
print(call_int_int_temp[int](add, 3, 7)) # works just fine

cppyy.cppdef(r"""
int call_int_int(int (*f)(int, int), int i1, int i2) {
    return f(i1, i2);
}
""")

from cppyy.gbl import call_int_int
print(call_int_int(sumc, 3, 7)) # works fine
print(call_int_int(lambda x, y: x*y, 3, 7)) # works fine

Still checking other cases. Hopefully fixes them all. :D

Update: for all Python callbacks I've tried, this seems to do the trick. Other symbol materialization issues related to static initialization are a different problem.

Gabrielcarvfer added a commit to Gabrielcarvfer/ns-3-dev that referenced this issue Oct 19, 2023
Gabrielcarvfer added a commit to Gabrielcarvfer/ns-3-dev that referenced this issue Oct 20, 2023
@wlav
Copy link
Owner

wlav commented Nov 2, 2023

I can not reproduce the problem with all provided docker images/examples, but where I can, I confirm that the fix found by @Gabrielcarvfer solves the issue (many, many, thanks for that!).

I simplified it to:

+       gInterpreter->Declare(
+           "#if defined(__GLIBCXX__)\n"
+           "template std::string::pointer  std::string::_M_use_local_data();\n"
+            "template std::wstring::pointer std::wstring::_M_use_local_data();\n"
+           "#endif\n"
+        );

in src/clingwrapper.cxx.

This has been a long run ... with this one, the Mac issue, and the gcc12 problem resolved (famous last words :) ), I can finally cut a release. Again, many thanks!

@wlav
Copy link
Owner

wlav commented Nov 2, 2023

Just to add to my own optimistic message: likely the reason that it was not reproducible with some docker images, is that the two offending methods were introduced only with gcc12.

@wlav
Copy link
Owner

wlav commented Nov 13, 2023

Should all be good now with release 3.1.0. Feel free to reopen if you find otherwise.

@wlav wlav closed this as completed Nov 13, 2023
@N-Coder
Copy link

N-Coder commented Nov 14, 2023

Bad news, I still get this with ogdf-python on my Fedora 38...

$ python -m ogdf_python
[runStaticInitializersOnce]: Failed to materialize symbols: { (main, { _ZN4ogdfL17s_ogdfInitializerE, __orc_init_func.cling-module-150, _GLOBAL__sub_I_cling_module_150, __cxx_global_var_initcling_module_150_, $.cling-module-150.__inits.0 }) }
[runStaticInitializersOnce]: Failed to materialize symbols: { (main, { __orc_init_func.cling-module-150 }) }
[runStaticInitializersOnce]: Failed to materialize symbols: { (main, { _ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_, _ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED1Ev, _GLOBAL__sub_I_cling_module_162, $.cling-module-162.__inits.0, _ZN9get_macro16var_OGDF_VERSIONB5cxx11E, __cxx_global_var_initcling_module_162_, __orc_init_func.cling-module-162 }) }
[runStaticInitializersOnce]: Failed to materialize symbols: { (main, { __orc_init_func.cling-module-162 }) }
cling JIT session error: Failed to materialize symbols: { (main, { _ZN9get_macro16var_OGDF_VERSIONB5cxx11E }) }
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/tmp/venv/lib64/python3.11/site-packages/ogdf_python/__main__.py", line 5, in <module>
    pprint(get_ogdf_info(), sort_dicts=False)
           ^^^^^^^^^^^^^^^
  File "/tmp/venv/lib64/python3.11/site-packages/ogdf_python/info.py", line 63, in get_ogdf_info
    "ogdf_version": get_macro("OGDF_VERSION").strip('"'),
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'strip'
$ python
Python 3.11.6 (main, Oct  3 2023, 00:00:00) [GCC 13.2.1 20230728 (Red Hat 13.2.1-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from ogdf_python import *
[runStaticInitializersOnce]: Failed to materialize symbols: { (main, { _GLOBAL__sub_I_cling_module_150, $.cling-module-150.__inits.0, _ZN4ogdfL17s_ogdfInitializerE, __cxx_global_var_initcling_module_150_, __orc_init_func.cling-module-150 }) }
[runStaticInitializersOnce]: Failed to materialize symbols: { (main, { __orc_init_func.cling-module-150 }) }
>>> G = ogdf.Graph()
>>> print(G)
<cppyy.gbl.ogdf.Graph object at 0x55a35712c770>
$ pip freeze
cppyy==3.1.0
cppyy-backend==1.15.0
cppyy-cling==6.30.0
CPyCppyy==1.12.14
ogdf-python==0.3.0
ogdf-wheel==2023.9
$ uname -a
Linux escher 6.5.10-200.fc38.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Nov  2 19:59:55 UTC 2023 x86_64 GNU/Linux
$ lsb_release -a
LSB Version:	:core-4.1-amd64:core-4.1-noarch
Distributor ID:	Fedora
Description:	Fedora release 38 (Thirty Eight)
Release:	38
Codename:	ThirtyEight

Good news is that seems that even though these warnings, many things seem to work again, although that needs further testing. My Observer example from here is not working:

$ python
Python 3.11.6 (main, Oct  3 2023, 00:00:00) [GCC 13.2.1 20230728 (Red Hat 13.2.1-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from cppyy import *
>>> import cppyy.gbl as c
>>> 
>>> include("test.cpp")
[runStaticInitializersOnce]: Failed to materialize symbols: { (main, { _ZN10MyObserverC2Ev, _ZTV8Observer, _ZN10MyObserverD1Ev, _ZTI8Observer, _ZTV10MyObserver, _ZN8ObserverD0Ev, _ZN10MyObserverD0Ev, _ZNSt7__cxx114listIP8ObserverSaIS2_EED1Ev, main, __orc_init_func.cling-module-146, _ZN8ObserverD1Ev, _ZN8Observer12onRegisteredEP10Observable, _ZTI10MyObserver, __clang_call_terminate, _ZN8ObserverD2Ev, _ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_, __cxx_global_var_initcling_module_146_, _ZTS10MyObserver, _ZN10MyObserverD2Ev, _ZN10MyObserver11onThingDoneERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE, long_lived_obs, $.cling-module-146.__inits.0, _GLOBAL__sub_I_cling_module_146, _ZN10MyObserver12onRegisteredEP10Observable, _ZTS8Observer, _ZN8Observer7observeEP10Observable }) }
True
>>> 
>>> class MyObserver(c.Observer):
...     def onThingDone(self, msg):
...         print(id(self), "onThingDone", msg)
...     def onRegistered(self, prev):
...         print(id(self), "onRegistered", "was", prev, "is", self.observed)
... 
>>> 
>>> obj = c.Observable()
[runStaticInitializersOnce]: Failed to materialize symbols: { (main, { __orc_init_func.cling-module-146 }) }
>>> obs = MyObserver()
cling JIT session error: Failed to materialize symbols: { (main, { _ZN8Observer7observeEP10Observable }) }
cling JIT session error: Failed to materialize symbols: { (main, { _ZTVN16__cppyy_internal11Dispatcher1E }) }
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: none of the 2 overloaded methods succeeded. Full details:
  none of the 3 overloaded methods succeeded. Full details:
  Dispatcher1::Dispatcher1(const __cppyy_internal::Dispatcher1& other) =>
    TypeError: takes at least 1 arguments (0 given)
  Dispatcher1::Dispatcher1(const Observer& a0) =>
    TypeError: takes at least 1 arguments (0 given)
  __cppyy_internal::Dispatcher1 constructor failed
  none of the 3 overloaded methods succeeded. Full details:
  Dispatcher1::Dispatcher1(const __cppyy_internal::Dispatcher1& other) =>
    TypeError: takes at least 1 arguments (0 given)
  Dispatcher1::Dispatcher1(const Observer& a0) =>
    TypeError: takes at least 1 arguments (0 given)
  __cppyy_internal::Dispatcher1 constructor failed
>>> obs
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'obs' is not defined. Did you mean: 'obj'?
>>> exit()
cling JIT session error: Failed to materialize symbols: { (main, { _ZN8Observer7observeEP10Observable }) }

@wlav
Copy link
Owner

wlav commented Nov 14, 2023

:(

@wlav wlav reopened this Nov 14, 2023
@wlav
Copy link
Owner

wlav commented Nov 14, 2023

Can you check the output of:

$ python
>>> import cppyy
>>> cppyy.cppexec("std::cerr << __GLIBCXX__ << std::endl;")

I'm curious (hoping, rather) whether it's something as simple as me having the cutoff incorrect of the GLIBCXX where the problem started.

@Gabrielcarvfer
Copy link

Got an error on Ubuntu 22.04 with GCC 11.4.0

>>> import cppyy
input_line_10:2:45: error: explicit instantiation of '_M_use_local_data' does not refer to a function template, variable template, member function, member class, or static data member
template std::string::pointer  std::string::_M_use_local_data();
                                            ^
input_line_10:3:46: error: explicit instantiation of '_M_use_local_data' does not refer to a function template, variable template, member function, member class, or static data member
template std::wstring::pointer std::wstring::_M_use_local_data();
                                             ^
>>> cppyy.cppexec("std::cerr << __GLIBCXX__ << std::endl;")
20230528
True
>>> 

But it is working for me on Ubuntu 23.04

Python 3.11.4 (main, Jun  9 2023, 07:59:55) [GCC 12.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cppyy
>>> cppyy.cppexec("std::cout << __GLIBCXX__ << std::endl;")
20230510
True
>>> 

@wlav
Copy link
Owner

wlav commented Nov 14, 2023

That error is coming from:

       gInterpreter->Declare(
           "#if defined(__GLIBCXX__) && __GLIBCXX__ >= 20220506\n"
           "template std::string::pointer  std::string::_M_use_local_data();\n"
           "template std::wstring::pointer std::wstring::_M_use_local_data();\n"
           "#endif\n"
        );

where that __GLIBCXX__ is supposed to check for the presence of _M_use_local_data, which is the cause of the symbols not materializing. I guess that the check isn't working as I expected to identify the presence of that method (it was introduced at some point in gcc11).

@wlav
Copy link
Owner

wlav commented Nov 14, 2023

Looks like issue with std::allocator<char>, not with that std::string constructor itself (which just uses it). Also, this Fedora system has gcc13, so may have had further changes that the original report didn't fix.

@wlav
Copy link
Owner

wlav commented Nov 14, 2023

In fact, if I remove all other workarounds and just add this at the top of the script (after importing cppyy), then things run fine for me on the Fedora docker image (don't know yet about the others):

cppyy.cppdef("template class std::allocator<char>;")

Edit: even better: I can add the above to the clingwrapper.cxx file so that the compiler (as opposed to the JIT) instantiates it. The JIT then finds it as an ordinary linker symbol. It does not seem to require the same for std::string and std::wstring, but I can add these for good measure. (The advantage of doing this in the .cxx, is that there's no risk of errors for duplicate explicit instantiations, as there is for the JIT, and by using the standard classes rather than the implementation-specific methods, I don't need to do a version check.)

@N-Coder
Copy link

N-Coder commented Nov 14, 2023

@wlav I could create a PR to set up GitHub Actions CI in this repo to continuously perform (at least smoke) tests on different OSes and versions (say latest and oldest supported Ubuntu, Debian and Fedora via Docker and also MacOs and Windows). Test coverage may be extendable but just checking for exceptions or warnings on startup or with a handful of simple use-cases (eg from the docs or from GitHub issues to check for regressions) might be a good start. It might be a little more challenging to bring all things together and in-sync with the split across different packages and repos that we have here, so I'd initially gear this towards checking (almost) released versions for problems on individual OSes or trying new things based on a released configuration instead of testing everything live alongside development. How would that sound to you? If you're open to this (you can still easily ignore the CI if you don't care for that) I'd happily draft a PR to set this up.

@N-Coder
Copy link

N-Coder commented Nov 14, 2023

Oh, and the cppdef seems to have fixed it!

$ python
Python 3.11.6 (main, Oct  3 2023, 00:00:00) [GCC 13.2.1 20230728 (Red Hat 13.2.1-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cppyy
>>> cppyy.cppexec("std::cerr << __GLIBCXX__ << std::endl;")
20231011
True
>>> cppyy.cppdef("template class std::allocator<char>;")
True
>>> from cppyy import *
>>> import cppyy.gbl as c
>>> 
>>> include("test.cpp")
0x7f48446e0000 construct
True
>>> class MyObserver(c.Observer):
...     def onThingDone(self, msg):
...         print(id(self), "onThingDone", msg)
...     def onRegistered(self, prev):
...         print(id(self), "onRegistered", "was", prev, "is", self.observed)
... 
>>> 
>>> obj = c.Observable()
>>> obs = MyObserver()
>>> exit()
0x7f48446e0000 destruct
$ # edit in your cppdef("template class std::allocator<char>;") into the ogdf_python loader...
$ python -m ogdf_python
[runStaticInitializersOnce]: Failed to materialize symbols: { (main, { $.cling-module-151.__inits.0, __cxx_global_var_initcling_module_151_, _ZN4ogdfL17s_ogdfInitializerE, _GLOBAL__sub_I_cling_module_151, __orc_init_func.cling-module-151 }) }
[runStaticInitializersOnce]: Failed to materialize symbols: { (main, { __orc_init_func.cling-module-151 }) }
{'ogdf_path': '/tmp/venv/lib64/libOGDF.so', ...}

While there still is a warning for ogdf_python, the library now seems to be loaded correctly and working. You don't happen to have similar fix ready for s_ogdfInitializer, have you? My attempt at simply copying it from the source code lead to redefinition errors...


Edit: interestingly, turning off the declaration of static Initialization s_ogdfInitializer in that header by doing #define OGDF_INSTALL before loading it also fixed the remaining warnings (it now loads completely without warnings!). Unfortunately I'm not quite sure about all consequences of this, so I don't know whether this somewhat hacky fix is the way to go...

@wlav
Copy link
Owner

wlav commented Nov 14, 2023

For CI, yes that may work, but it's a bit convoluted to build from source when not everything is released b/c of the way pip deals (or rather not deals) with dependencies. cppyy 4.0.0 (based on clang-repl) should be consolidated, but is some way off (upstream says that about half the tests succeed; I haven't worked on it myself yet). Building the full backend (which includes LLVM) is also costly and doesn't work on platforms such as manylinux which insists on using a pre-C++11 ABI. :( Maybe something that can run the full test-suite manually just prior to a release? (Note that the test-suite is only 100% error free on Linux and Mac; there are a handful of errors on Windows left.)

For the static initializer, there is this: cms-sw/cmssw#43077 (comment) so upstream is working on that (and they have to care alot about CMS software ;) ). (Yes, I've seen your edit, but there's something real still there.)

I'm going to cut a new release later today (a fix in clingwrapper is easy to release, which is why it exists as a separate package, but ironically enough this is the first time since its existence I'm making use of that). I just want to get this one done as well: #191, since I'm now on this Fedora image anyway where it's easy to reproduce.

@wlav
Copy link
Owner

wlav commented Nov 14, 2023

Release 3.1.1 works for me (famous last words) on that Fedora docker image ...

@N-Coder
Copy link

N-Coder commented Nov 14, 2023

Things are looking very good now on Fedora. Install works flawlessly, I only get the warning from the ogdf initializer, and the Observer example now exits cleanly with only the warning "sys:1: RuntimeWarning: Call attempted on deleted python-side proxy". So both issues are now resolved from my point of view.


As you are already building cppyy-cling wheels in CI and the rest is easy to install, I threw together this script which should work on debian, ubuntu and fedora docker containers to set up all components with their latest repo versions. Currently, this fails with the following error on all three systems:

  File "/venv/lib64/python3.11/site-packages/cppyy_backend/loader.py", line 92, in load_cpp_backend
    raise RuntimeError("could not load cppyy_backend library, details:\n%s" %
RuntimeError: could not load cppyy_backend library, details:
  libcppyy_backend.cpython-311-x86_64-linux-gnu.so: cannot open shared object file: No such file or directory
  /venv/lib64/python3.11/site-packages/cppyy_backend/lib/libcppyy_backend.cpython-311-x86_64-linux-gnu.so: cannot open shared object file: No such file or directory
  /venv/lib64/python3.11/site-packages/cppyy_backend/lib/libcppyy_backend.so: undefined symbol: _ZN11CppyyLegacy10TClassEdit9CleanTypeB5cxx11EPKciPS2_
  libcppyy_backend.so: cannot open shared object file: No such file or directory

So it seems the four components are currently somehow in an inconsistent state. Still, I'll set up a CI pipeline around this next and ensure that there are options to only run the versions from PyPi and to manually trigger such runs. I'll open a new issue for this once there is further progress...

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

4 participants