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

pyroot problem with std::vector of enum

    XMLWordPrintable

Details

    Description

      hi -

      In root 6.04.12, pyroot isn't correctly handling std::vector of enumeration
      types.

      Consider these declarations (test.cc):

      #include <vector>
      enum E { a, b };
      std::vector<E> v;

      Then:

      $ python
      >>> import ROOT
      >>> import cppyy
      >>> ROOT.gROOT.LoadMacro('test.cc')
      0
      >>> ROOT.v.data()
      Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
      SystemError: none of the 2 overloaded methods succeeded. Full details:
        E* vector<E>::data() =>
          NULL result without error in mp_call
        const E* vector<E>::data() =>
          NULL result without error in mp_call
      >>> list(ROOT.v)
       
       *** Break *** segmentation violation

      What's happening: In PyROOT::CreateExecutor, we try to find a converter for the
      return type of the data() function, which in this case is `E*'.
      This function has a special case to recognize enum types:

         } else if ( Cppyy::IsEnum( realType ) ) {
         // enums don't resolve to unsigned ints, but that's what they are ...
            h = gExecFactories.find( "UInt_t" + cpd );

      so it transforms the type to `UInt_t*'. However, there is no such type
      registered in gExecFactories. We have `unsigned int*', but not `UInt_t*'.

      This patch fixes the problem:

      diff --git a/bindings/pyroot/src/Executors.cxx b/bindings/pyroot/src/Executors.cxx
      index 8cd2f22..932f4c1 100644
      --- a/bindings/pyroot/src/Executors.cxx
      +++ b/bindings/pyroot/src/Executors.cxx
      @@ -707,6 +707,7 @@ namespace {
             NFp_t( "unsigned short*",    &CreateUShortArrayExecutor         ),
             NFp_t( "int*",               &CreateIntArrayExecutor            ),
             NFp_t( "unsigned int*",      &CreateUIntArrayExecutor           ),
      +      NFp_t( "UInt_t*",            &CreateUIntArrayExecutor           ),
             NFp_t( "long*",              &CreateLongArrayExecutor           ),
             NFp_t( "unsigned long*",     &CreateULongArrayExecutor          ),
             NFp_t( "float*",             &CreateFloatArrayExecutor          ),

      Attachments

        Activity

          People

            axel Axel Naumann
            ssnyder Scott Snyder
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: