destructors: already-unregistered error had the wrong content, also don't throw an error when disposing a disposable twice
parent
623ddfca6f
commit
adc154e06b
|
@ -1,5 +1,5 @@
|
||||||
USING: destructors kernel tools.test continuations accessors
|
USING: destructors kernel tools.test continuations accessors
|
||||||
namespaces sequences ;
|
namespaces sequences destructors.private ;
|
||||||
IN: destructors.tests
|
IN: destructors.tests
|
||||||
|
|
||||||
TUPLE: dispose-error ;
|
TUPLE: dispose-error ;
|
||||||
|
@ -66,3 +66,12 @@ M: dummy-destructor dispose ( obj -- )
|
||||||
] ignore-errors destroyed?>>
|
] ignore-errors destroyed?>>
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
|
TUPLE: silly-disposable < disposable ;
|
||||||
|
|
||||||
|
M: silly-disposable dispose* drop ;
|
||||||
|
|
||||||
|
silly-disposable new-disposable "s" set
|
||||||
|
"s" get dispose
|
||||||
|
[ "s" get unregister-disposable ]
|
||||||
|
[ disposable>> silly-disposable? ]
|
||||||
|
must-fail-with
|
||||||
|
|
|
@ -21,7 +21,7 @@ SLOT: continuation
|
||||||
disposables get conjoin ;
|
disposables get conjoin ;
|
||||||
|
|
||||||
: unregister-disposable ( obj -- )
|
: unregister-disposable ( obj -- )
|
||||||
disposables get 2dup key? [ already-unregistered ] unless delete-at ;
|
disposables get 2dup key? [ delete-at ] [ drop already-unregistered ] if ;
|
||||||
|
|
||||||
PRIVATE>
|
PRIVATE>
|
||||||
|
|
||||||
|
@ -49,7 +49,11 @@ M: object dispose
|
||||||
dup disposed>> [ drop ] [ t >>disposed dispose* ] if ;
|
dup disposed>> [ drop ] [ t >>disposed dispose* ] if ;
|
||||||
|
|
||||||
M: disposable dispose
|
M: disposable dispose
|
||||||
[ unregister-disposable ] [ call-next-method ] bi ;
|
dup disposed>> [ drop ] [
|
||||||
|
[ unregister-disposable ]
|
||||||
|
[ call-next-method ]
|
||||||
|
bi
|
||||||
|
] if ;
|
||||||
|
|
||||||
: dispose-each ( seq -- )
|
: dispose-each ( seq -- )
|
||||||
[
|
[
|
||||||
|
|
|
@ -152,4 +152,10 @@ USE: debugger.threads
|
||||||
"non-byte-array-error" unique-file binary [
|
"non-byte-array-error" unique-file binary [
|
||||||
"" write
|
"" write
|
||||||
] with-file-writer
|
] with-file-writer
|
||||||
] [ no-method? ] must-fail-with
|
] [ no-method? ] must-fail-with
|
||||||
|
|
||||||
|
! What happens if we close a file twice?
|
||||||
|
[ ] [
|
||||||
|
"closing-twice" unique-file ascii <file-writer>
|
||||||
|
[ dispose ] [ dispose ] bi
|
||||||
|
] unit-test
|
Loading…
Reference in New Issue