From 6d6b1642cbd1fe6cbc0f71215b3ffc207187e63b Mon Sep 17 00:00:00 2001 From: Steve Kelly Date: Fri, 19 Apr 2024 18:44:04 -0400 Subject: [PATCH] register `atexit` hook on module `_init_` These hooks are usually registered at module `_init_`, partially to make the code easier to reason about. Though this now has greater significance with improved static compilation techniques, since the _init_ is the module entry and anything outside will be discarded from what I can tell. --- src/Curl/Curl.jl | 1 + src/Curl/Multi.jl | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Curl/Curl.jl b/src/Curl/Curl.jl index 3fc9310..ebd402d 100644 --- a/src/Curl/Curl.jl +++ b/src/Curl/Curl.jl @@ -67,6 +67,7 @@ include("utils.jl") function __init__() @check curl_global_init(CURL_GLOBAL_ALL) + Base.atexit(atexit_close_multis) end const CURL_VERSION_INFO = unsafe_load(curl_version_info(CURLVERSION_NOW)) diff --git a/src/Curl/Multi.jl b/src/Curl/Multi.jl index c6ed079..67d9798 100644 --- a/src/Curl/Multi.jl +++ b/src/Curl/Multi.jl @@ -56,7 +56,7 @@ end const MULTIS_LOCK = Base.ReentrantLock() const MULTIS = WeakRef[] # Close any Multis and their timers at exit that haven't been finalized by then -Base.atexit() do +function atexit_close_multis() while true w = @lock MULTIS_LOCK (isempty(MULTIS) ? nothing : pop!(MULTIS)) w === nothing && break