ext/sender/rb_Global.c in sender-1.0.1 vs ext/sender/rb_Global.c in sender-1.1.0

- old
+ new

@@ -1,19 +1,27 @@ -#include <ruby.h> - #include "rb_Global.h" -#include "rb_Global_internal.h" // Internals from ruby that aren't included in the ruby lib #include "RubySourceSupport.h" #include "eval_intern.h" +/*********** +* Global * +***********/ + +void Init_senderGlobal() { + + rb_define_global_function( "__sender__", rb_RPRuby_Sender___sender__, 0 ); + rb_define_global_function( "__caller__", rb_RPRuby_Sender___caller__, 0 ); + +} + /*************************************************************************************************************************************************************** **************************************************************************************************************************************************************** - Global Ruby Methods + Ruby Global Methods **************************************************************************************************************************************************************** ***************************************************************************************************************************************************************/ /*************** * __sender__ * @@ -23,19 +31,21 @@ * call-seq: * __sender__ -> object * * Return object sending message to receiver. */ -VALUE rb_RPRuby_SenderCaller__sender__() { +VALUE rb_RPRuby_Sender___sender__() { - rb_control_frame_t* c_sending_frame = RPRuby_internal_framePriorToCurrent(); + // get the frame prior to current frame + rb_control_frame_t* c_sending_frame = RPRuby_internal_framePriorTo( NULL ); + // make sure the current frame wasn't the first frame or return nil if ( c_sending_frame == NULL ) { return Qnil; } - // return rb_self that is sender + // assuming we have a previous frame, return its rb_self (our current receiver's sender) return c_sending_frame->self; } /*************** * __caller__ * @@ -45,32 +55,10 @@ * call-seq: * __caller__ -> object * * Return method sending message to receiver. */ -VALUE rb_RPRuby_SenderCaller__caller__() { +VALUE rb_RPRuby_Sender___caller__() { return ID2SYM( rb_frame_caller() ); } -/*************************************************************************************************************************************************************** -**************************************************************************************************************************************************************** - Internal Methods -**************************************************************************************************************************************************************** -***************************************************************************************************************************************************************/ - -/************************* - * framePriorToCurrent * - ************************/ - -rb_control_frame_t* RPRuby_internal_framePriorToCurrent() { - - rb_thread_t* c_thread = GET_THREAD(); - rb_control_frame_t* prior_control_frame = RUBY_VM_PREVIOUS_CONTROL_FRAME( c_thread->cfp ); - - // Make sure we actually have a prior frame - if ( (void*)( c_thread->stack + c_thread->stack_size ) == (void*)( prior_control_frame ) ) { - return NULL; - } - - return prior_control_frame; -}