Skip to content

Commit f632a0e

Browse files
Remove top-level calls to LibGC.has_method? for backwards compat (#15635)
`has_method?` in top-level macro expressions was broken before Crystal 1.7.0 (fixed in #12848). On older compiler versions `LibGC.has_method?(:set_stackbottom)` would always return `false` and break assumptions about available lib symbols. This patch simply moves the macro expression into the `def` body. We don't need this on the top level. More details in #15633 (comment)
1 parent 22c5ce8 commit f632a0e

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

src/gc/boehm.cr

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -431,21 +431,21 @@ module GC
431431
sb.mem_base = stack_bottom
432432
LibGC.set_stackbottom(thread_handle, pointerof(sb))
433433
end
434-
{% elsif LibGC.has_method?(:set_stackbottom) %}
435-
# this is necessary because Boehm GC does _not_ use `GC_stackbottom` on
436-
# Windows when pushing all threads' stacks; it also started crashing on
437-
# Linux with libgc after v8.2.4; instead `GC_set_stackbottom` must be used
438-
# to associate the new bottom with the running thread
439-
def self.set_stackbottom(stack_bottom : Void*)
440-
sb = LibGC::StackBase.new
441-
sb.mem_base = stack_bottom
442-
# `nil` represents the current thread (i.e. the only one)
443-
LibGC.set_stackbottom(nil, pointerof(sb))
444-
end
445434
{% else %}
446-
# support for legacy gc releases
447435
def self.set_stackbottom(stack_bottom : Void*)
448-
LibGC.stackbottom = stack_bottom
436+
\{% if LibGC.has_method?(:set_stackbottom) %}
437+
# this is necessary because Boehm GC does _not_ use `GC_stackbottom` on
438+
# Windows when pushing all threads' stacks; it also started crashing on
439+
# Linux with libgc after v8.2.4; instead `GC_set_stackbottom` must be used
440+
# to associate the new bottom with the running thread
441+
sb = LibGC::StackBase.new
442+
sb.mem_base = stack_bottom
443+
# `nil` represents the current thread (i.e. the only one)
444+
LibGC.set_stackbottom(nil, pointerof(sb))
445+
\{% else %}
446+
# support for legacy gc releases
447+
LibGC.stackbottom = stack_bottom
448+
\{% end %}
449449
end
450450
{% end %}
451451

0 commit comments

Comments
 (0)