-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* allow for value of a declared integer to be a value that has
a destructor. This fixes ticket:937.
- Loading branch information
Shawn David Pringle, B.Sc.
committed
Dec 30, 2024
1 parent
5f6c867
commit 793ba70
Showing
8 changed files
with
128 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
include std/io.e | ||
include std/error.e | ||
include std/unittest.e | ||
with trace | ||
trace(1) | ||
|
||
|
||
type enum boolean T,F=0 end type | ||
type file_number(integer x) | ||
return x >= -1 | ||
end type | ||
|
||
boolean enable_my_close = F | ||
|
||
procedure my_close(integer fh) | ||
if fh > io:STDERR then | ||
-- Closing file | ||
if not enable_my_close then | ||
test_fail("premature file closing") | ||
end if | ||
close(fh) | ||
end if | ||
test_pass("dstor called") | ||
end procedure | ||
|
||
procedure do_nothing(integer bool) | ||
end procedure | ||
|
||
-- Make sure a user defined type that is integer based can have routine_ids too. | ||
procedure use_integer_with_dtor() | ||
file_number 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 | ||
end procedure | ||
|
||
enable_my_close = T | ||
|
||
-- dtor will be called when this routine exits. | ||
use_integer_with_dtor() | ||
|
||
|
||
enable_my_close = F | ||
file_number 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 | ||
-- dtor will be executed by changing its value to a new one. | ||
f_debug = -1 | ||
|
||
|
||
enable_my_close = F | ||
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 | ||
-- dtor will be executed by changing its value to a new one. | ||
f_debug += 1 | ||
|
||
test_report() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
include std/unittest.e | ||
|
||
type enum boolean | ||
FALSE=0,TRUE | ||
end type | ||
|
||
boolean cleanedup = FALSE | ||
|
||
procedure cleanup_now(object in_put) | ||
cleanedup = TRUE | ||
end procedure | ||
|
||
integer fd = open("t_autoclose.e", "r", 1) | ||
|
||
test_pass( "able to assign integers to integer with destructors" ) | ||
|
||
function wrapper() | ||
return delete_routine(4, routine_id("cleanup_now")) | ||
end function | ||
|
||
integer other = wrapper() | ||
|
||
other = 3 | ||
|
||
test_equal("Cleaned up called", TRUE, cleanedup) | ||
test_report() |