Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

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

未关闭
#20,952 2 条评论 0 个 reaction 已指派 2 人 在 GitHub 查看

维护者通常 1 天内回复

@guitargeek 已经在做这个了。

开始于 2026年1月19日。

评估

这个 Issue 还没有评估数据。

描述

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

主要语言
C++
星标
3.3k
派生
1.6k
平均合并
2 天 16 小时
30 天内合并 PR
194

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

root-project/root 的其他 Issue

查看 root-project/root 的全部 Issue

相似的 Issue

更多 C++ Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。