Skip to content

Commit 013116e

Browse files
committedMar 30, 2016
Properly guard managed objects on stack while loading code.
1 parent 78013da commit 013116e

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed
 

‎machine/arguments.hpp

+8
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ namespace rubinius {
5858
, argument_container_(0)
5959
{}
6060

61+
Arguments(Symbol* name, Object* recv, Array* ary)
62+
: name_(name)
63+
, recv_(recv)
64+
, block_(cNil)
65+
{
66+
use_array(ary);
67+
}
68+
6169
Arguments(Symbol* name, Array* ary)
6270
: name_(name)
6371
, recv_(cNil)

‎machine/marshal.cpp

+18-8
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "dispatch.hpp"
88
#include "memory.hpp"
99
#include "marshal.hpp"
10+
#include "on_stack.hpp"
1011

1112
#include "object_utils.hpp"
1213

@@ -96,13 +97,16 @@ namespace rubinius {
9697
}
9798

9899
Object* UnMarshaller::get_rational() {
99-
Object* objs[2];
100+
Object* a;
101+
Object* b;
102+
OnStack<2> os(state, a, b);
100103

101-
objs[0] = unmarshal();
102-
objs[1] = unmarshal();
104+
a = unmarshal();
105+
b = unmarshal();
103106

104107
Symbol* name = state->symbol("unmarshal_rational");
105-
Arguments args(name, G(runtime), 2, objs);
108+
Arguments args(name, G(runtime),
109+
Array::from_tuple(state, Tuple::from(state, 2, a, b)));
106110
Dispatch dispatch(name);
107111

108112
if(Object* r = dispatch.send(state, args)) {
@@ -113,13 +117,16 @@ namespace rubinius {
113117
}
114118

115119
Object* UnMarshaller::get_complex() {
116-
Object* objs[2];
120+
Object* a;
121+
Object* b;
122+
OnStack<2> os(state, a, b);
117123

118-
objs[0] = unmarshal();
119-
objs[1] = unmarshal();
124+
a = unmarshal();
125+
b = unmarshal();
120126

121127
Symbol* name = state->symbol("unmarshal_complex");
122-
Arguments args(name, G(runtime), 2, objs);
128+
Arguments args(name, G(runtime),
129+
Array::from_tuple(state, Tuple::from(state, 2, a, b)));
123130
Dispatch dispatch(name);
124131

125132
if(Object* c = dispatch.send(state, args)) {
@@ -186,6 +193,7 @@ namespace rubinius {
186193
stream >> count;
187194

188195
Tuple* tup = state->memory()->new_fields<Tuple>(state, G(tuple), count);
196+
OnStack<1> os(state, tup);
189197

190198
if(tup->young_object_p()) {
191199
for(size_t i = 0; i < count; i++) {
@@ -266,6 +274,7 @@ namespace rubinius {
266274

267275
InstructionSequence* iseq = InstructionSequence::create(state, count);
268276
Tuple* ops = iseq->opcodes();
277+
OnStack<2> os(state, iseq, ops);
269278

270279
for(size_t i = 0; i < count; i++) {
271280
stream.getline(data, OPCODE_LENGTH);
@@ -283,6 +292,7 @@ namespace rubinius {
283292
stream >> ver;
284293

285294
CompiledCode* code = CompiledCode::create(state);
295+
OnStack<1> os(state, code);
286296

287297
code->metadata(state, unmarshal());
288298
code->primitive(state, force_as<Symbol>(unmarshal()));

0 commit comments

Comments
 (0)
Please sign in to comment.