Skip to content

Commit 2b4034b

Browse files
committed
Move initailizing animals out of __init__ to global scope.
Having `__init__` read from the filesystem was causing problems with static compiling. Per the julia docs, intializing an array like this doesn't need to be in __init__, the whole array can be serialized during precompilation: > Constants involving most Julia objects that are not produced by ccall > do not need to be placed in __init__: their definitions can be > precompiled and loaded from the cached module image. This includes > complicated heap-allocated objects like arrays. However, any routine > that returns a raw pointer value must be called at runtime for > precompilation to work (Ptr objects will turn into null pointers > unless they are hidden inside an isbits object). This includes the > return values of the Julia functions cfunction and pointer.
1 parent e8bd6b1 commit 2b4034b

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/MacroTools.jl

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,10 @@ include("examples/forward.jl")
1919
const animals = Symbol[]
2020
const animals_file = joinpath(dirname(@__FILE__), "..", "animals.txt")
2121

22-
function __init__()
23-
_animals = split(read(animals_file, String))
24-
resize!(animals, length(_animals))
25-
animals .= Symbol.(lowercase.(_animals))
26-
Compat.Random.shuffle!(animals)
27-
end
22+
# Load and initialize animals symbols.
23+
_animals = split(read(animals_file, String))
24+
resize!(animals, length(_animals))
25+
animals .= Symbol.(lowercase.(_animals))
26+
Compat.Random.shuffle!(animals)
2827

2928
end # module

0 commit comments

Comments
 (0)