8
8
#include " builtin/variable_scope.hpp"
9
9
#include " call_frame.hpp"
10
10
#include " ontology.hpp"
11
+ #include " on_stack.hpp"
11
12
12
13
namespace rubinius {
13
14
void Location::init (STATE) {
@@ -82,11 +83,22 @@ namespace rubinius {
82
83
return loc;
83
84
}
84
85
85
- Array* Location::from_call_stack (STATE, CallFrame* start_call_frame ,
86
+ Array* Location::from_call_stack (STATE, CallFrame* call_frame ,
86
87
bool include_vars, bool on_ip)
87
88
{
88
- Array* bt = Array::create (state, 5 );
89
- CallFrame* call_frame = start_call_frame;
89
+ size_t count = 0 ;
90
+
91
+ CallFrame* c = call_frame;
92
+ while (c) {
93
+ if (c->compiled_code ) count++;
94
+ c = c->previous ;
95
+ }
96
+
97
+ Array* bt = 0 ;
98
+ Location* loc = 0 ;
99
+ OnStack<2 > os (state, bt, loc);
100
+
101
+ bt = Array::create (state, count);
90
102
91
103
// Initial edge.
92
104
if (!call_frame) return bt;
@@ -98,7 +110,7 @@ namespace rubinius {
98
110
if (!call_frame) return bt;
99
111
}
100
112
101
- Location* loc = Location::create (state, call_frame, include_vars);
113
+ loc = Location::create (state, call_frame, include_vars);
102
114
if (on_ip) loc->set_ip_on_current (state);
103
115
104
116
bt->append (state, loc);
@@ -110,7 +122,7 @@ namespace rubinius {
110
122
if (call_frame->compiled_code ) {
111
123
bt->append (state, Location::create (state, call_frame, include_vars));
112
124
} else if (NativeMethodFrame* nmf = call_frame->native_method_frame ()) {
113
- Location* loc = Location::create (state, nmf);
125
+ loc = Location::create (state, nmf);
114
126
if (loc) bt->append (state, loc);
115
127
}
116
128
@@ -121,6 +133,9 @@ namespace rubinius {
121
133
}
122
134
123
135
Array* Location::mri_backtrace (STATE, CallFrame* call_frame) {
136
+ Array* bt = 0 ;
137
+ OnStack<1 > os (state, bt);
138
+
124
139
size_t count = 0 ;
125
140
126
141
CallFrame* c = call_frame;
@@ -129,7 +144,7 @@ namespace rubinius {
129
144
c = c->previous ;
130
145
}
131
146
132
- Array* bt = Array::create (state, count);
147
+ bt = Array::create (state, count);
133
148
134
149
while (call_frame) {
135
150
// Ignore synthetic frames
0 commit comments