Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GC.enable: raise if GC is not disabled #4945

Merged
merged 2 commits into from Sep 15, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions spec/std/gc_spec.cr
Expand Up @@ -4,4 +4,10 @@ describe "GC" do
it "compiles GC.stats" do
typeof(GC.stats).should eq(GC::Stats)
end

it "raises if calling enable when not disabled" do
expect_raises do
GC.enable
end
end
end
5 changes: 5 additions & 0 deletions src/gc/boehm.cr
Expand Up @@ -20,6 +20,7 @@ lib LibGC
fun add_roots = GC_add_roots(low : Void*, high : Void*)
fun enable = GC_enable
fun disable = GC_disable
fun is_disabled = GC_is_disabled : Int
fun set_handle_fork = GC_set_handle_fork(value : Int)

fun base = GC_base(displaced_pointer : Void*) : Void*
Expand Down Expand Up @@ -85,6 +86,10 @@ module GC
end

def self.enable
unless LibGC.is_disabled != 0
raise "GC.enable: GC is not disabled"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should already know we're in GC.enable from the stacktrace. We don't prefix with the method name in other parts of the stdlib at least.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The stack trace I get is:

GC is not disabled (Exception)
0x108ef5695: *CallStack::unwind:Array(Pointer(Void)) at ??
0x108ef5631: *CallStack#initialize:Array(Pointer(Void)) at ??
0x108ef5608: *CallStack::new:CallStack at ??
0x108ee4d55: *raise<Exception>:NoReturn at ??
0x108ee4d01: *raise<String>:NoReturn at ??
0x108f126ff: *GC::enable:Nil at ??
0x108ee47f4: __crystal_main at ??
0x108ef48c8: main at ??

Seems pretty cryptic to me. The call for GC::enable is like 6 lines below.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a whole another issue, but it doesn't have to be this way.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about "Can't enable GC: GC is not disabled". I mean, there's nothing wrong with being just a bit more verbose, right?

end

LibGC.enable
end

Expand Down