Re: Interesting Problem
- Posted by mattlewis (admin) Apr 21, 2010
- 1429 views
This started out with many lines of code. The problem is that I get a machine level error. The error handler points to the switch statement. I removed one line of code at a time to get to what you see. Remove ANY line of code and the problem disappears. Change the order of the lines and the problem disappears. If anyone is interested I can send the error file. The japi.e include file is a euphoria wrapper for GUI code from www.japi.de via rapideuphoria's archive. Euphoria 4.0 Ubuntu 9.xx It smells like a pointer or stack problem. Also note that if you replace the symbol btn in the case statement with its value (integer 4) the problem goes away.
I pared it down a bit more:
function foo( ) return 3 end function constant bar = foo() integer obj = 2 switch obj do case 1 then case bar then case else end switch
This has been fixed in svn:3179. See ticket:152. Basically, since you're using a constant that is assigned via a function, the value of the constant isn't known at compile time, so the interpreter has to do some work at run time (the first time the switch is seen) to convert it into a real switch.
For the type of switch we have here (all integers in a relatively small rang), the jump table uses relative offsets. It has an entry for each integer from the smallest to the largest case. Any missing value points to the else (or the end of the switch if there is no else). The interpreter was using an absolute address for the missing case values.
If you can't rebuild from svn, there are a couple of things you can do to work around this:
- Never pass a missing value (this probably won't work for you, or you wouldn't have found this in the first place)
- Add something like case "" then to your switch. This will cause the case statement to be implemented differently (essentially, using find() on the case values. This is slower than the optimized version that only has integers as case values, but your code should work.
Matt