Skip to content

cling failure when accessing std::map elements from Python #20952

@vepadulano

Description

@vepadulano

Check duplicate issues.

  • Checked for duplicates

Description

Consider the following program

import ROOT

ROOT.gInterpreter.Declare(r"""

struct S{};

std::map<std::string, std::vector<std::unique_ptr<S>>> mymap;
mymap["a"] = std::vector<std::unique_ptr<S>>();
""")

# For some reason, uncommenting the following line will prevent the program from crashing
# print(ROOT.mymap)

for key, value in ROOT.mymap:
    print(key, value)

Running this program in master shows no issues:

$: python test_map.py 
a {}

But I suspect there is a real problem hidden in this code. By applying this simple patch #20946, the same program crashes

 *** Break *** illegal instruction
[...]
make_dtor_wrapperFailed to compile
==== SOURCE BEGIN ====
__attribute__((used)) extern "C" void __dtor_0(void* obj, unsigned long nary, int withFree)
{
   if (withFree) {
      if (!nary) {
         delete (std::_Rb_tree_iterator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::vector<std::unique_ptr<S, std::default_delete<S> >, std::allocator<std::unique_ptr<S, std::default_delete<S> > > > > >*) obj;
      }
      else {
         delete[] (std::_Rb_tree_iterator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::vector<std::unique_ptr<S, std::default_delete<S> >, std::allocator<std::unique_ptr<S, std::default_delete<S> > > > > >*) obj;
      }
   }
   else {
      typedef std::_Rb_tree_iterator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::vector<std::unique_ptr<S, std::default_delete<S> >, std::allocator<std::unique_ptr<S, std::default_delete<S> > > > > > Nm;
if (!nary) {
         ((Nm*)obj)->~Nm();
      }
      else {
         do {
            (((Nm*)obj)+(--nary))->~Nm();
         } while (nary);
      }
   }
}

I attach the full stacktrace here

full_stacktrace.txt

Something that looks odd is the presence of const std::basic_string in part of the output from above, while the std::map I create uses just std::basic_string, I don't know if it's related to the issue.

Reproducer

See above

ROOT version

Master with patch #20946

Installation method

Build from source

Operating system

Linux

Additional context

No response

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions