Skip to content

TGraph::Clone() crashes when called from Python on a TGraph object created in C++ #21973

@SergueiEK

Description

@SergueiEK

Check duplicate issues.

  • Checked for duplicates

Description

In Python, calling Clone() method of a TGraph object created in c++ library crashes with the following messages:

Traceback (most recent call last):
  File "./test.py", line 12, in <module>
    g.Clone()
  File "/cvmfs/sft.cern.ch/lcg/releases/LCG_108a/ROOT/6.36.04/x86_64-el9-gcc14-opt/lib/ROOT/_pythonization/_memory_utils.py", line 45, in _Clone_releasing_ownership
    if _should_give_up_ownership(out):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/cvmfs/sft.cern.ch/lcg/releases/LCG_108a/ROOT/6.36.04/x86_64-el9-gcc14-opt/lib/ROOT/_pythonization/_memory_utils.py", line 19, in _should_give_up_ownership
    tdir = object.GetDirectory()
           ^^^^^^^^^^^^^^^^^^^
AttributeError: 'TGraph' object has no attribute 'GetDirectory'

Reproducer

The following code must be compiled into libfast_plugin.so library:

#include <TGraph.h>

namespace fast_plugin {

    TGraph* get_graph() {
        auto g = new TGraph();
        g->SetNameTitle("Test Graph", "No title");
        return g;
    }
}

The following code can be used to reproduce the crash:

import ROOT

exported_functions = 'namespace fast_plugin { TH1* get_graph();}'
ROOT.gInterpreter.ProcessLine(exported_functions)
ROOT.gSystem.Load('libfast_plugin.so')

namespace = getattr(ROOT, 'fast_plugin')
func = getattr(namespace, 'get_graph')

g = func()
print(g)
g.Clone()

ROOT version

ROOT 6.36.04

Installation method

/cvmfs/sft.cern.ch/lcg/releases/LCG_108a/ROOT/6.36.04/x86_64-el9-gcc14-opt

Operating system

Linux 5.14.0-570.44.1.el9_6.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Sep 17 10:32:11 EDT 2025 x86_64 x86_64 x86_64 GNU/Linux

Additional context

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions