Cppyy segfault importing c++ class

ROOT Version: 6.24.06
Platform: Centos Stream 8
Compiler: g++ 8.5.0
Python: 3.8.13

Hello everyone.
I’m trying to add python integration into an application using cppyy, but having a hard time getting it working. Although strictly nothing I’m doing involves ROOT classes or functions, since cppyy is being provideed by ROOT the suggestion from the cppyy maintainers has been to ask here. So here goes…

Since nothing appears to be working, I’ve worked my way down to a minimal tester, which also does not work.
I have a simple c++ class, which I compile into a library, load the library in python, and then try to import the class. The result is a segmentation violation pointing to libCling.so.

the code: pydebug.zip (1.8 KB)

Within test.py there are two lines commented out that import the DataModel class. Uncommenting either produces the following stacktrace:

[root@build-01 try1]$ python3 test2.py                                                                                        
Missing transaction during deserialization!
UNREACHABLE executed at /ToolAnalysis/ToolDAQ/root-6.24.06/interpreter/cling/lib/Interpreter/DeclCollector.cpp:68!
 *** Break *** abort
 *** Break *** abort

Just in case there was any doubt (though the code is pretty simple), I’ve tried this on another system, using the latest cppyy independent of ROOT, and it works without issue, so this definitely seems to be something specifically to do with the installation, setup, or ROOT’s cppyy version.

A little more info on this; trying things from the command prompt seems to reveal the problem specifically lies with cling’s ability to parse the class header.
As described on the cppyy user guide, it’s sufficient to load the header in order to explore the class. In a working installation, I can indeed do:

$ python3
>>> import cppyy
>>> cppyy.add_include_path('/path/to/DataModel')
>>> cppyy.include('DataModel.h')
>>> dir(cppyy.gbl.DataModel)

to see the accessible attributes of the class, even before the library is loaded.
With the ROOT installation, this same code segfaults.

Thank you for your report. We will investigate the problem, but can you maybe open a ROOT GitHub issue on this so we will keep track of it ?


Thanks for the response Lorenzo. I may hold off on that just for a bit, as I’ve managed to get the minimal reproducer working by generating a dictionary with rootcling and compiling that into the the library. working.zip (1.3 KB)

As far as I can tell this shouldn’t technically be necessary - it’s not a requirement from the cppyy side, and the ROOT page on IO of custom classes says no dictionary should be needed for interactive use either. Still, with a dictionary generated by rootcling built into the library, it works.

So far so good for the minimal reproducer.

Moving back to my actual application introduces more complexities, though, and there I’m still having trouble. Even with a dictionary included, modifying simple integer members works, but getting the size of a map<int,int> returns garbage. On the other hand, a minimal reproducer is able to modify both types without problems, so i’m slowly pulling things apart to see what’s different. I’ll update when I have more progress.


OK, well the thread closed over Christmas, but here’s the finale.

I’m afraid I can’t remember now how I solved the map size thing - perhaps some user error. However after solving that, I still found that on cleanup, after all the code had run, it would segmentation fault and/or spew out thousands of errors about corrupted double-linked list.
I eventually discovered this was a result of:

  1. python being called from c++. Calling the python code (which uses c++ classes via cppyy) with python3 test.py always worked fine. Using the Python API to call the same test.py from c++ also worked unless
  2. A particular class was linked in to the calling c++ application as well. Specifically, this class had a static TF1 member. After replacing the static TF1 member with a static TF1* initialised on first use, everything now seems to be working ok (as far as i can see).

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.