From 18bbfc70a7d8b872c495c1402ede703674ba99df Mon Sep 17 00:00:00 2001 From: Kristoffer Date: Thu, 25 Apr 2024 11:03:49 +0200 Subject: [PATCH] prevent `package_callbacks` to run multiple time for a package --- base/loading.jl | 2 +- test/precompile.jl | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/base/loading.jl b/base/loading.jl index 86cad6f2ed94d..d30767d5d1f22 100644 --- a/base/loading.jl +++ b/base/loading.jl @@ -2273,7 +2273,7 @@ function __require_prelocked(uuidkey::PkgId, env=nothing) run_package_callbacks(uuidkey) else m = get(loaded_modules, uuidkey, nothing) - if m !== nothing + if m !== nothing && !haskey(explicit_loaded_modules, uuidkey) explicit_loaded_modules[uuidkey] = m run_package_callbacks(uuidkey) end diff --git a/test/precompile.jl b/test/precompile.jl index ffd6e24789aba..27a20931dafbb 100644 --- a/test/precompile.jl +++ b/test/precompile.jl @@ -1331,6 +1331,25 @@ precompile_test_harness("package_callbacks") do dir finally pop!(Base.package_callbacks) end + Test5_module = :Teste4095a85 + write(joinpath(dir, "$(Test5_module).jl"), + """ + module $(Test5_module) + end + """) + Base.compilecache(Base.PkgId("$(Test5_module)")) + cnt = 0 + push!(Base.package_callbacks, _->(cnt += 1)) + try + @eval using $(Symbol(Test5_module)) + @eval using $(Symbol(Test5_module)) + @eval using $(Symbol(Test5_module)) + @eval using $(Symbol(Test5_module)) + @eval using $(Symbol(Test5_module)) + @test cnt == 1 + finally + pop!(Base.package_callbacks) + end end # Issue #19960