Report abuse

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
diff --git a/vm/builtin/nativemethod.cpp b/vm/builtin/nativemethod.cpp
index 38a7400..1f1084b 100644
--- a/vm/builtin/nativemethod.cpp
+++ b/vm/builtin/nativemethod.cpp
@@ -181,7 +181,7 @@ namespace rubinius {
   }

   Object* NativeMethodEnvironment::block() {
-    return current_block_;
+    return current_block_.get();
   }

   capi::HandleList& NativeMethodEnvironment::handles() {
@@ -216,7 +216,7 @@ namespace rubinius {
   }

   void NativeMethod::init_thread(STATE) {
-    NativeMethodEnvironment* env = new NativeMethodEnvironment;
+    NativeMethodEnvironment* env = new NativeMethodEnvironment(state);
     env->set_state(state);
     native_method_environment.set(env);
   }
diff --git a/vm/builtin/nativemethod.hpp b/vm/builtin/nativemethod.hpp
index 64d14d8..1d1187a 100644
--- a/vm/builtin/nativemethod.hpp
+++ b/vm/builtin/nativemethod.hpp
@@ -38,9 +38,14 @@ namespace rubinius {
     /** Current native callframe. */
     NativeMethodFrame*  current_native_frame_;
     ExceptionPoint*     current_ep_;
-    Object*             current_block_;
+    TypedRoot<Object*>  current_block_;

   public:   /* Class Interface */
+    NativeMethodEnvironment(STATE)
+      : current_block_(state)
+    {
+      current_block_.set(Qnil);
+    }

     /** Obtain the NativeMethodEnvironment for this thread. */
     static NativeMethodEnvironment* get();
@@ -65,7 +70,7 @@ namespace rubinius {
     Object* block();

     void set_current_block(Object* block) {
-      current_block_ = block;
+      current_block_.set(block);
     }

     void set_state(VM* vm) {