Skip to content

Commit 91268e0

Browse files
committed
Don't rely on implicit binding creation of setglobal!
The `mod.sym = val` syntax is not supposed to be able to create new bindings if `mod.sym` does not yet exist. The error check for this was accidentally dropped in Julia 1.9, but will likely be put back in 1.11 [1]. This uses Core.eval/invokelatest to achieve the same effect using the recommeded replacement. As a general note, the way this package uses bindings is clever, but not particularly idiomatic in Julia. Not saying you can't do it, but I would recommend revisiting if at least the injected bindings could perhaps be replaced by something like an IdDict. [1] JuliaLang/julia#54678
1 parent 700ed57 commit 91268e0

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/core.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,6 +1143,19 @@ function start! end
11431143

11441144
function start!(mod::Module = Main, ip::IP4 = ip4_cli(Main.ARGS);
11451145
threads::Int64 = 1, router_threads::UnitRange{Int64} = -2:threads)
1146+
1147+
# Inject bindings we will use into the module
1148+
if !isdefined(mod, :server)
1149+
Core.eval(mod, :(global server, data, routes))
1150+
1151+
# Switch to the latest world where the bindings are available
1152+
invokelatest(_start!, mod, ip, threads, router_threads)
1153+
else
1154+
_start!(mod, ip, threads, router_threads)
1155+
end
1156+
end
1157+
1158+
function _start!(mod::Module, ip::IP4, threads::Int64, router_threads::UnitRange{Int64})
11461159
IP = Sockets.InetAddr(parse(IPAddr, ip.ip), ip.port)
11471160
server::Sockets.TCPServer = Sockets.listen(IP)
11481161
mod.server = server
@@ -1210,6 +1223,7 @@ function generate_router(mod::Module, ip::IP4)
12101223
mod.routes = Vector{AbstractRoute}()
12111224
loaded = []
12121225
for name in server_ns
1226+
isdefined(mod, name) || continue
12131227
f = getfield(mod, name)
12141228
T = typeof(f)
12151229
if T <: AbstractExtension

0 commit comments

Comments
 (0)