Skip to content

Commit

Permalink
Properly guard managed objects on stack while loading code.
Browse files Browse the repository at this point in the history
  • Loading branch information
brixen committed Mar 30, 2016
1 parent 78013da commit 013116e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
8 changes: 8 additions & 0 deletions machine/arguments.hpp
Expand Up @@ -58,6 +58,14 @@ namespace rubinius {
, argument_container_(0)
{}

Arguments(Symbol* name, Object* recv, Array* ary)
: name_(name)
, recv_(recv)
, block_(cNil)
{
use_array(ary);
}

Arguments(Symbol* name, Array* ary)
: name_(name)
, recv_(cNil)
Expand Down
26 changes: 18 additions & 8 deletions machine/marshal.cpp
Expand Up @@ -7,6 +7,7 @@
#include "dispatch.hpp"
#include "memory.hpp"
#include "marshal.hpp"
#include "on_stack.hpp"

#include "object_utils.hpp"

Expand Down Expand Up @@ -96,13 +97,16 @@ namespace rubinius {
}

Object* UnMarshaller::get_rational() {
Object* objs[2];
Object* a;
Object* b;
OnStack<2> os(state, a, b);

objs[0] = unmarshal();
objs[1] = unmarshal();
a = unmarshal();
b = unmarshal();

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

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

Object* UnMarshaller::get_complex() {
Object* objs[2];
Object* a;
Object* b;
OnStack<2> os(state, a, b);

objs[0] = unmarshal();
objs[1] = unmarshal();
a = unmarshal();
b = unmarshal();

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

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

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

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

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

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

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

code->metadata(state, unmarshal());
code->primitive(state, force_as<Symbol>(unmarshal()));
Expand Down

0 comments on commit 013116e

Please sign in to comment.