cs: allow unsafe finalizers on managed objects
Change the regular weak reference in a custodian, which allows `will-executor`-based finalization, to a "late" weakk reference, which allows both `will-executor` and `register-finalizer` finalization. Closes #3352
This commit is contained in:
parent
7b3850eab0
commit
91abd020d1
25
pkgs/racket-test/tests/racket/custodian-finalize-help.rkt
Normal file
25
pkgs/racket-test/tests/racket/custodian-finalize-help.rkt
Normal file
|
@ -0,0 +1,25 @@
|
|||
#lang racket/base
|
||||
(require ffi/unsafe/custodian)
|
||||
|
||||
;; This module is run by "custodian-finalize.rkt"
|
||||
|
||||
(define (log-info x)
|
||||
(log-message (current-logger) 'info 'finalize x))
|
||||
|
||||
(define (finalize x)
|
||||
(log-info "finalizing"))
|
||||
|
||||
(define the-box
|
||||
(let ([v (string-copy "a value")])
|
||||
(register-finalizer-and-custodian-shutdown v finalize #:at-exit? #t)
|
||||
(log-info "created")
|
||||
(box v)))
|
||||
|
||||
(module* check-gc #f
|
||||
(set-box! the-box #f)
|
||||
(collect-garbage 'major)
|
||||
(sync (system-idle-evt))
|
||||
(log-info "exiting"))
|
||||
|
||||
(module* check-exit #f
|
||||
(log-info "exiting"))
|
30
pkgs/racket-test/tests/racket/custodian-finalize.rkt
Normal file
30
pkgs/racket-test/tests/racket/custodian-finalize.rkt
Normal file
|
@ -0,0 +1,30 @@
|
|||
#lang racket/base
|
||||
(require compiler/find-exe
|
||||
racket/system)
|
||||
|
||||
(define racket (find-exe))
|
||||
|
||||
(define result 0)
|
||||
|
||||
(define (run/get-stderr . args)
|
||||
(define o (open-output-bytes))
|
||||
(parameterize ([current-error-port o])
|
||||
(apply system* racket args))
|
||||
(get-output-bytes o))
|
||||
|
||||
(define (check expect got)
|
||||
(unless (equal? expect got)
|
||||
(eprintf "Expected ~s,\n got ~s\n" expect got)
|
||||
(set! result 1)))
|
||||
|
||||
(check #"finalize: created\nfinalize: exiting\nfinalize: finalizing\n"
|
||||
(run/get-stderr "-W" "info@finalize"
|
||||
"-e"
|
||||
"(dynamic-require '(submod \"custodian-finalize-help.rkt\" check-exit) #f)"))
|
||||
|
||||
(check #"finalize: created\nfinalize: finalizing\nfinalize: exiting\n"
|
||||
(run/get-stderr "-W" "info@finalize"
|
||||
"-e"
|
||||
"(dynamic-require '(submod \"custodian-finalize-help.rkt\" check-gc) #f)"))
|
||||
|
||||
(exit result)
|
|
@ -5679,7 +5679,7 @@
|
|||
#f
|
||||
(let ((we_0
|
||||
(if (not weak?7_0)
|
||||
(|#%app| host:make-will-executor void)
|
||||
(|#%app| host:make-late-will-executor void)
|
||||
#f)))
|
||||
(begin
|
||||
(let ((app_0 (custodian-children cust12_0)))
|
||||
|
|
|
@ -122,7 +122,7 @@
|
|||
[(custodian-shut-down? cust) #f]
|
||||
[else
|
||||
(define we (and (not weak?)
|
||||
(host:make-will-executor void)))
|
||||
(host:make-late-will-executor void)))
|
||||
(hash-set! (custodian-children cust)
|
||||
obj
|
||||
(cond
|
||||
|
|
Loading…
Reference in New Issue
Block a user