Details
-
Bug
-
Status: Closed (View Workflow)
-
Medium
-
Resolution: Fixed
-
6.06/00
-
None
-
-
Description
In PyROOT, trying to iterate over a collection returned from a function can result in destruction of the collection before its iterators, e.g.
for elem in getset(): |
print(elem) |
will crash, whereas
s = getset() |
for elem in s: |
print(elem) |
, where s has a larger scope, will work as expected. (see attached test)
I was able to fix this by adding a _collection attribute to the iterator in StlSequenceIter(), which ensures the reference count for the collection cannot reach 0 before the iteration is finished.
std::vector is handled as a special case with its own iterator type by PyROOT and is not affected by this problem.