1. Interesting Problem

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.

Any thoughts? regards, jd

#! /home/jd/euphoria/bin/eui  
include japi.e as j 
include std/pretty.e as pe 
 
 
	if( j:j_start() = j:J_FALSE ) then		--sets up the engine 
	    puts(1,"can't connect to JAPI server") 
	    abort(1) 
	end if 
 
constant win1 = j:j_frame("Manage Categories") 
 
constant btn = j:j_button(win1,"SAVE") 
 
--j:j_show(win1) 
 
integer obj = 2		--values 2 & 3 do not work others do work <<-------------- 
sequence values 
 
values = {win1,btn}		--no effect on operation diagnostics only 
pe:pretty_print(1,values,{})	--no effect on operation diagnostics only 
 
	switch obj do		--this is line number 23 
		case 1 then 
 
		case btn then 
 
		case else 
 
	end switch 

The terminal output follows:

./test1.ex:23 
A machine-level exception occurred during execution of this statement  

new topic     » topic index » view message » categorize

2. Re: Interesting Problem

jessedavis said...

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

new topic     » goto parent     » topic index » view message » categorize

3. Re: Interesting Problem

mattlewis said...

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.

I'm glad you fixed this just now as I was about to start using this sort of construct in win32lib. smile

new topic     » goto parent     » topic index » view message » categorize

4. Re: Interesting Problem

Matt: Thanks for your super rapid reply. Are you guys really up at 3 a.m. working on this stuff?

Thanks again, jd

new topic     » goto parent     » topic index » view message » categorize

5. Re: Interesting Problem

jessedavis said...

Matt: Thanks for your super rapid reply. Are you guys really up at 3 a.m. working on this stuff?

It was more like 4am. Before work is often the best time for euphoria stuff, since the wife and kids are all still asleep.

Matt

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu