Ticket #937: assigning to integer destroys the object prematurely

new topic     » topic index » view thread      » older message » newer message

Hi

https://openeuphoria.org/ticket/937.wc

This raised a ton of questions for me

include std/io.e  
include std/error.e  
include std/unittest.e  
  
type enum boolean T,F=0 end type  
  
boolean enable_my_close = F  
  
procedure my_close(integer fh)  
    if fh > io:STDERR then  
    	printf(io:STDERR, "Closing file %d\n", {fh})  
    	if not enable_my_close then  
    		crash("premature file closing")  
    	end if  
        close(fh)  
    end if  
end procedure  
  
integer f_debug = open("example.log", "w")  
if f_debug =-1 then  
	f_debug = open("/dev/null", "w")  
  	puts(io:STDERR, "Unable to create log file.")  
else  
    f_debug = delete_routine(f_debug, routine_id("my_close"))  
end if  
  
enable_my_close = T  
  
test_report() 
 

My interpretation of this is :

  • call a routine with an integer as the first paremeter.
  • the way it should work is the integer is passed (in this case f_debug), enacted, and then cleaned up afterwards
  • the way the ticket implies it's working is that the integer is cleaned up straight away.
  • this is beacause the integer has at some point had something called a destructor added to it
  • and when this is present in this instance destroys the integer immediately on calling the routine.

Please correct me.

Is this still relevent?
Has it been fixed?
Why would anyone want to call a routine this way?

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu