Unexpected (to me) behavior of flex.bool
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
I think this always has been like this - all of the arrays (tiny, plain, shared) have constructures taking size and size + initialiser...
Since bool and int (False=0, True=anything but 0) are interconvertible in CPP - you may get a warning at compilation time but not much more. So, expect
flex.bool(2, 0) to create [False, False]
identical to the default initialiser:
flex.bool(2)
Cheers,
Oleg.
________________________________
From: [email protected]
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 _______________________________________________ cctbxbb mailing list [email protected] https://gbr01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fphenix-online.org%2Fmailman%2Flistinfo%2Fcctbxbb&data=05%7C01%7C%7Ca6bf98c4bb8a4470fabc08db6ee4f354%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C638225701830132779%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=6LAweRYvY1HaKpz%2BrY5G9vY4W7G1pM4al5fLaHEsSH4%3D&reserved=0http://phenix-online.org/mailman/listinfo/cctbxbb
participants (2)
-
Oleg Dolomanov
-
Pavel Afonine