Sha256: 3e8d4783b2088629ea11da2201f4d57f986018bd49209d3000bdab3c9f2e6d08

Contents?: true

Size: 1.55 KB

Versions: 3

Compression:

Stored size: 1.55 KB

Contents

#include "ruby.h"

static VALUE rb_mInterception;

extern struct FRAME {
    VALUE self;
    int argc;
    ID last_func;
    ID orig_func;
    VALUE last_class;
    struct FRAME *prev;
    struct FRAME *tmp;
    struct RNode *node;
    int iter;
    int flags;
    unsigned long uniq;
} *ruby_frame;

#ifdef RUBY_18

#include "node.h"

void
interception_hook(rb_event_t event, NODE *node, VALUE self, ID mid, VALUE klass)
{
    VALUE bself = ruby_frame->prev->self;
    if (node == ruby_frame->node) {
        bself = ruby_frame->prev->prev->self;
    }

    VALUE binding = rb_funcall(bself, rb_intern("binding"), 0, NULL);
    rb_funcall(rb_mInterception, rb_intern("rescue"), 2, ruby_errinfo, binding);
}

VALUE
interception_start(VALUE self)
{
    rb_add_event_hook(interception_hook, RUBY_EVENT_RAISE);
    return Qnil;
}

#else

void
interception_hook(rb_event_flag_t evflag, VALUE data, VALUE self, ID mid, VALUE klass)
{
    VALUE binding = rb_funcall(rb_mKernel, rb_intern("binding"), 0, NULL);
    rb_funcall(rb_mInterception, rb_intern("rescue"), 2, rb_errinfo(), binding);
}

VALUE
interception_start(VALUE self)
{
    rb_add_event_hook(interception_hook, RUBY_EVENT_RAISE, rb_mInterception);
    return Qnil;
}

#endif

VALUE
interception_stop(VALUE self)
{
    rb_remove_event_hook(interception_hook);
    return Qnil;
}

void
Init_interception()
{
    rb_mInterception = rb_define_module("Interception");
    rb_define_singleton_method(rb_mInterception, "start", interception_start, 0);
    rb_define_singleton_method(rb_mInterception, "stop", interception_stop, 0);
}

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
rake-builder-0.8.0 examples/04_zlib/vendor/bundle/gems/interception-0.3/ext/interception.c
rake-builder-0.7.0 examples/04_zlib/vendor/bundle/gems/interception-0.3/ext/interception.c
interception-0.3 ext/interception.c