[cctbxbb] Unexpected (to me) behavior of flex.bool

Pavel Afonine pafonine at lbl.gov
Fri Jun 16 20:42:47 PDT 2023


Hi All,

today it took me several hours to debug something that ended up being 
the result of this behavior:

 >>> from scitbx.array_family import flex
 >>> x = flex.bool(True, 5)
 >>> y = flex.bool(5, True)
 >>> list(x)
[True]
 >>> list(y)
[True, True, True, True, True]
 >>>

I needed to pass a flex.bool array (with all True) into a C++ function 
and I was doing it as "x" above. In that C++ function there was no size 
check for incoming arrays (bad idea!) and then later in the code when 
accessing elements of this flex.bool array I was getting "random" numbers!

I was pretty sure that flex.bool(True, 5) should lead to an assertion error!

Was this always like this (and I was just super-lucky to never run into 
this issue in the past 20 years) or something has changed?

Pavel




More information about the cctbxbb mailing list