Created
July 26, 2010 21:13
-
-
Save jakedouglas/491260 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/vm/capi/gc.cpp b/vm/capi/gc.cpp | |
index c6231e4..71c17a0 100644 | |
--- a/vm/capi/gc.cpp | |
+++ b/vm/capi/gc.cpp | |
@@ -55,6 +55,11 @@ extern "C" { | |
* to be in the heap. | |
*/ | |
void rb_gc_mark_maybe(VALUE ptr) { | |
- rb_gc_mark(ptr); | |
+ NativeMethodEnvironment* env = NativeMethodEnvironment::get(); | |
+ Handle* handle = Handle::from(ptr); | |
+ | |
+ if(capi::Handle::valid_handle_p(env->state(), handle)) { | |
+ rb_gc_mark(ptr); | |
+ } | |
} | |
} | |
diff --git a/vm/capi/handle.cpp b/vm/capi/handle.cpp | |
index dff1ea2..32e1f17 100644 | |
--- a/vm/capi/handle.cpp | |
+++ b/vm/capi/handle.cpp | |
@@ -5,6 +5,17 @@ | |
namespace rubinius { | |
namespace capi { | |
+ | |
+ bool Handle::valid_handle_p(STATE, Handle* handle) { | |
+ Handles* handles = state->shared.global_handles(); | |
+ | |
+ for(Handles::Iterator i(*handles); i.more(); i.advance()) { | |
+ if(i.current() == handle) return true; | |
+ } | |
+ | |
+ return false; | |
+ } | |
+ | |
void Handle::free_data() { | |
if(as_.cache_data) { | |
switch(type_) { | |
diff --git a/vm/capi/handle.hpp b/vm/capi/handle.hpp | |
index 06ab6e2..4f28c8e 100644 | |
--- a/vm/capi/handle.hpp | |
+++ b/vm/capi/handle.hpp | |
@@ -63,6 +63,8 @@ namespace rubinius { | |
as_.cache_data = 0; | |
} | |
+ static bool valid_handle_p(STATE, Handle* handle); | |
+ | |
~Handle(); | |
void flush(NativeMethodEnvironment* env) { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment