Skip to content

Commit

Permalink
Fix: require crystal/main sooner in prelude
Browse files Browse the repository at this point in the history
The interpreter on windows segfaults because `Crystal::Once.init` wasn't
called soon enough:

- require "string"
- require "string/builder"
- require "io"
- require "io/file_descriptor"
- require "crystal/system/win32/file_descriptor"
- at_exit <== inlined call!
- Crystal::AtExitHandlers#class_getter(handlers) { ... } <== calls Crystal.once!
- (...)
- require "crystal/main"
- Crystal.init_runtime
- Crystal::Once.init <== only initialized now!

Requiring crystal/main sooner makes sure that the interpreter will
execute `Crystal.init_runtime` before any other inlined call that may
depend on `Crystal.once`.
  • Loading branch information
ysbaddaden committed Jan 30, 2025
1 parent a888edb commit b057f50
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/prelude.cr
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
require "lib_c"
require "macros"
require "object"
require "crystal/main"
require "crystal/once"
require "comparable"
require "exception"
Expand All @@ -34,7 +35,6 @@ require "char/reader"
require "class"
require "concurrent"
require "crystal/compiler_rt"
require "crystal/main"
require "deque"
require "dir"
require "enum"
Expand Down

0 comments on commit b057f50

Please sign in to comment.