Segfault when inheriting from both a PYROOT obj and a built-in python type

Hello PyROOT users. The following code generates a segfault:

class C(ROOT.TH1F, str): pass

Apparently this happens because I am inheriting from “str”.

The following code, where I inherit instead from a user-defined class, runs without any problem:

class A: pass

class C(ROOT.TH1F, A): pass

The error occurs only when I create a class that inherits from both a PyROOT object and a built-in python type. Can any of you provide insight as to why this happens?

Thank you.

You get a crash b/c the old version of cppyy that is still internal to PyROOT does not check the subtype in the metaclass instance (i.e. class) creation. With current cppyy, you get a python exception explaining the problem: both cppyy bound classes and classes such as the builtins carry a payload on the C side. Thus, the allocator (implemented by their type type, i.e. the metaclass) needs to create space for both. That requires a proper resolution, which doesn’t exist:

TypeError: Error when calling the metaclass bases
    multiple bases have instance lay-out conflict

Either way, it won’t work unless you reimplement tp_new in a metaclass for the derived type that inherits from both other metaclasses. You can’t quite do that in python (you can do the creation and reimplementation, but not the allocation and initialization: internal data members are hidden).


1 Like

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