Exemplo n.º 1
0
  Object* Thread::raise(STATE, Exception* error) {
    wakeup(state);

    MethodContext* ctx = task_->active();
    ctx->reference(state);
    error->context(state, ctx);

    return task_->raise(state, error);
  }
Exemplo n.º 2
0
  void test_reference() {
    MethodContext* ctx = MethodContext::create(state, 10);
    TS_ASSERT(!state->om->context_referenced_p(ctx));
    TS_ASSERT_EQUALS(ctx->klass_, Qnil);

    ctx->reference(state);

    TS_ASSERT_EQUALS(ctx->klass(), G(methctx));
    TS_ASSERT(state->om->context_referenced_p(ctx));

    MethodContext* ctx2 = MethodContext::create(state, 10);
    TS_ASSERT(ctx != ctx2);
  }
Exemplo n.º 3
0
  NativeMethodContext* NativeMethodContext::create(VM* state,
                                                   Message* msg,
                                                   Task* task,
                                                   NativeMethod* method)
  {
    NativeMethodContext* nmc = state->new_struct<NativeMethodContext>(
        G(nativectx), DEFAULT_STACK_SIZE);

    /* MethodContext stuff. */
    MethodContext* sender = task->active();
    sender->reference(state);
    nmc->sender(state, sender);
    nmc->home(state, nmc);
    nmc->self(state, msg->recv);
    nmc->module(state, msg->module);
    nmc->name(state, msg->name);
    nmc->block(state, msg->block);

    /* Fake that which is not needed. */
    nmc->cm(state, reinterpret_cast<CompiledMethod*>(Qnil));
    nmc->vmm = NULL;

    /* Instead of storing the memory within as MethodContexts, we heap-allocate. */
    nmc->stack_size = DEFAULT_STACK_SIZE;

    nmc->action_          = ORIGINAL_CALL;
    nmc->handles_         = new HandleStorage();
    nmc->message_         = msg;
    nmc->message_from_c_  = new Message(state);
    nmc->method_          = method;
    nmc->return_value_    = Qnil;
    nmc->stack_           = static_cast<void*>(new char[nmc->stack_size]);
    nmc->state_           = state;
    nmc->task_            = task;

    nmc->current_file_    = ::strdup("<no file set>");
    nmc->current_line_    = 0;

    /* Add the basic Handles. Always crossref with ruby.h when changing. */
    nmc->handles_->push_back(Qfalse);
    nmc->handles_->push_back(Qtrue);
    nmc->handles_->push_back(Qnil);
    nmc->handles_->push_back(Qundef);

    nmc->message_from_c_->set_caller(nmc);

    return nmc;
  }