Created
April 23, 2015 12:01
-
-
Save ssvb/c5e77d87b5d2b0d10302 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/gc/boehm.cr b/src/gc/boehm.cr | |
index bc05474..d692a28 100644 | |
--- a/src/gc/boehm.cr | |
+++ b/src/gc/boehm.cr | |
@@ -16,6 +16,8 @@ lib LibGC | |
type Finalizer = Void*, Void* -> | |
fun register_finalizer = GC_register_finalizer(obj : Void*, fn : Finalizer, cd : Void*, ofn : Finalizer*, ocd : Void**) | |
fun invoke_finalizers = GC_invoke_finalizers : Int32 | |
+ fun set_finalize_on_demand = GC_set_finalize_on_demand(value : Int32) | |
+ fun get_finalize_on_demand = GC_get_finalize_on_demand : Int32 | |
fun get_heap_usage_safe = GC_get_heap_usage_safe(heap_size : LibC::SizeT*, free_bytes : LibC::SizeT*, unmapped_bytes : LibC::SizeT*, bytes_since_gc : LibC::SizeT*, total_bytes : LibC::SizeT*) | |
fun set_max_heap_size = GC_set_max_heap_size(LibC::SizeT) | |
@@ -78,7 +80,12 @@ module GC | |
->(obj, data) { | |
same_object = obj as T | |
if same_object.responds_to?(:finalize) | |
+ old_finalize_on_demand = LibGC.get_finalize_on_demand | |
+ # Prevent nested finalize calls, triggered by potential | |
+ # memory (re)allocation operations in finalizers | |
+ LibGC.set_finalize_on_demand(1) | |
same_object.finalize | |
+ LibGC.set_finalize_on_demand(old_finalize_on_demand) | |
end | |
}, nil, nil, nil) | |
nil |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment