Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

cling failure when accessing `std::map` elements from Python

Aperta
#20,952 2 commenti 0 reazioni 2 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@guitargeek ci sta già lavorando.

Dal 19/1/2026.

Valutazione

Questa issue non è ancora stata valutata.

Descrizione

bug in:Cling in:Python Interface
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 https://github.com/root-project/root/pull/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 https://github.com/root-project/root/pull/20946

Installation method

Build from source

Operating system

Linux

Additional context

No response

Lingua principale
C++
Stelle
3.3k
Fork
1.6k
Merge medio
2g 16h
PR unite (30g)
194

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di root-project/root

Tutte le issue di root-project/root

Issue simili

Altre issue su C++

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.