wlav / cppyy

Other
390 stars 40 forks source link

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

Open guitargeek opened 1 month ago

guitargeek commented 1 month 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.