[visionegg] Obscure bug in visionegg
- From: Dav Clark <davclark@xxxxxxxxxxxx>
- To: visionegg@xxxxxxxxxxxxx
- Date: Wed, 13 Aug 2008 16:54:31 -0700
Hi Andrew and the rest...
I've come across a strange bug in the ParameterTypes.py file in
VisionEgg (1.1). The following code illustrates a crash:
import VisionEgg
from VisionEgg.Text import Text
s = VisionEgg.Core.get_default_screen()
t = Text()
t.set(text='test')
If you look at the logic of ParameterTypes.get_type (line 326), you
see that before testing if 'test' is a string, it's tested to see if
it's a 4-item sequence, and then the string ends up as a Sequence4x4.
A bit confusing, but it happens because substrings (like 'test'[0])
are also sequences, and so pass the relatively weak test on line 331
of ParameterTypes.py. It would be a lot easier to simply throw the
thing at numpy.array and see if something sensible comes back.
So, in the code snippet above, t.set obtains that 'test' is a
Sequence4x4 (which it's not!). Then, on line 387 of
ParameterTypes.py, we catch an exception from assert_type each time
through, which leads to control flowing eventually to line 397, where
an undefined reference is made to require_class. So your program
crashes with the rather nonintuitive UnboundLocalError. This would
happen whenever an AnyOf type is not satisfied...
I guess you should raise a TypeError after the for loop ends (i.e.
after line 391 of ParameterTypes.py, dedented two stops, similar to
line 410)?
I could provide a patch, but the fix for assert_type is trivial, and
otherwise I'm not exactly sure what the right thing to do is here...
For example, I'm not sure any code expects to see these Sequence4x4
types. The only reference I can find to the type is in a comment on
line 1054 of Core.PerspectiveProjection - the type doesn't actually
seem to be used anywhere. More generally, it seems like there is type-
related stuff left over that is now completely unused - probably a
shift to using more standardized (python and numpy) types and shape
attributes would be in order... I understand why the code developed
it's own types, since types in python weren't great until at least
python 2.3, which came out a year after VisionEgg. But now it seems
the only useful one is "AnyOf".
I'm also happy to submit a bug to your Trac, but there don't seem to
be any real active tickets there... the only ticket being one that (I
think) you already accomplished!
For now, the fix is simply not to use Parameter 'safe' code with
string or "AnyOf" types, because it's actually quite dangerous!
This is a platform independent issue, but just for your reference, I'm
running on OSX 10.5.4. with the system python (2.5.1). (Why am I
running on the system python, you may ask? It's so I can use PyObjC 2
to control the bTop2 USB A/D box I've got).
Let me know how I can help!
Dav
ps - I've written a wrapper around VisionEgg which I'd like to share -
will anyone be at SciPy 2008? Might be a nice way to get some initial
feedback.
======================================
The Vision Egg mailing list
Archives: http://www.freelists.org/archives/visionegg
Website: http://www.visionegg.org/mailinglist.html
- Follow-Ups:
- [visionegg] Re: Obscure bug in visionegg
- From: Andrew Straw
Other related posts:
- » [visionegg] Obscure bug in visionegg
- » [visionegg] Re: Obscure bug in visionegg
- [visionegg] Re: Obscure bug in visionegg
- From: Andrew Straw