wlav / cppyy

Other
413 stars 42 forks source link

`std::vector` from C++ behaves unexpectedly in conjuncion with `array.array` #248

Closed guitargeek closed 3 months ago

guitargeek commented 4 months ago

Reported originally on the ROOT forum: https://root-forum.cern.ch/t/incompatibilities-with-array-array-introduced-in-root-6-32/59782

Reproducer:

import cppyy
import array

v1 = cppyy.gbl.std.vector("int")()

a = array.array('i', [1])

# This unexpectedly turns v1 into an iterator
v1+=a

print(v1, v1[0])

v1 = cppyy.gbl.std.vector("int")()

v1.assign(a)

print(v1, v1[0])

b = array.array('i', [])

# This will crash
v1.assign(b)

print(v1)

Output:

 1852402787
{ 1 } 1
 *** Break *** floating point exception

Expected output (using the pretty-printing of std::vector from PyROOT):

{ 1 } 1
{ 1 } 1
{}

In fact, the expected behavior was occurring with a previous cppyy version used before ROOT 6.32. Therefore, this issue is a behavior regression that catches uses by surprise.

guitargeek commented 3 months ago

The issue is fortunately gone with the most recent version of ROOT master and cppyy master.