Euphoria
Ticket #890:
functions passed to delete_routine exits the program
-
Reported by
SDPringle
Feb 13, 2014
This code exits unexpectedly.
include std/os.e
enum KEYBOARD = 0, SCREEN
function bad_cleanup_routine(object x)
puts(SCREEN, "cleanup\n")
return 0
end function
function new_object_with_cleanup()
return delete_routine(1, routine_id("bad_cleanup_routine"))
end function
integer x = new_object_with_cleanup()
x = 4
while x do
puts(SCREEN, "It's working.\n")
x = x - 1
sleep(1)
end while
We expect to see
It's working
It's working
It's working
It's working
but we get instead:
nothing!
The user shouldn't pass a function as a cleanup routine. It should be a procedure. Garbage in garbage out but this is EUPHORIA. It would be good if we could catch this error and display ex.err instead of exiting the program.
I argue this is a bug but others might see it differently.
Details
1. Comment by mattlewis
Feb 13, 2014
I agree. We should check to make sure we get a good routine id.
2. Comment by ChrisB
Nov 27, 2022
confirmed with
include std/os.e
enum KEYBOARD = 0, SCREEN
procedure bad_cleanup_routine(object x)
puts(SCREEN, "cleanup\n")
end procedure
function new_object_with_cleanup()
return delete_routine(1, routine_id("bad_cleanup_routine"))
end function
integer x = new_object_with_cleanup()
x = 4
while x do
new_object_with_cleanup()
puts(SCREEN, "It's working.\n")
x = x - 1
sleep(0.2)
end while
Calling a function from delete_routine() should emit a warning.