Uploaded image for project: 'ROOT'
  1. ROOT
  2. ROOT-10855

Cannot cast shared_ptr<T> to shard_ptr<const T> in PyROOT

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: High
    • Resolution: Fixed
    • Affects Version/s: 6.20/06
    • Fix Version/s: 6.22/00
    • Component/s: PyROOT
    • Labels:
    • Environment:
      • macOS 10.15.5
      • Python 3.7.6 (Homebrew)
      • Apple clang 11.0.3

       

    • Development:

      Description

      Conversion from std::shared_ptr<TGraph> to std::shared_ptr<const TGraph> works in C++.

      #include <memory>
      #include "TGraph.h"
       
      void foo(std::shared_ptr<const TGraph> gra) {
        gra->Dump();
      }
       
      void test() {
        auto graph = std::make_shared<TGraph>();
        foo(graph);
      }
      

      $ root
      root [0] .x test.C+
      ==> Dumping object at: 0x00007ffa37c785c8, name=, class=TGraph
       
      fMaxSize                      0                   !Current dimension of arrays fX and fY 
      (snip)
      

      But it doesn't in PyROOT.

      import ROOT
       
      ROOT.gInterpreter.Declare('void foo(shared_ptr<const TGraph> gra) {gra->Dump();}')
      ROOT.gROOT.ProcessLine('auto graph = std::make_shared<TGraph>();')
      ROOT.foo(ROOT.graph)
      

      In [1]: %run test.py                                                                                                   --------------------------------------------------------------------------- TypeError                                 Traceback (most recent call last) ~/test.py in <module>
            3 ROOT.gInterpreter.Declare('void foo(shared_ptr<const TGraph> gra) {gra->Dump();}')
            4 ROOT.gROOT.ProcessLine('auto graph = std::make_shared<TGraph>();')
      ----> 5 ROOT.foo(ROOT.graph)
            6
            7
      TypeError: void ::foo(shared_ptr<const TGraph> gra) =>
         could not convert argument 1
      

      I remember it was working a while ago, when Wim advised me to use gInterpreter.ProcessLine in this thread.

      https://root-forum.cern.ch/t/root-std-shared-ptr-in-python/35021

        Attachments

          Activity

            People

            Assignee:
            etejedor Enric Tejedor Saavedra
            Reporter:
            5634f7f540ef3ba1605e oxon@mac.com
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: