Sha256: 48c82a1bd0ceaf56b43cf4ba1eea8ad8789d24d83cdf967d1c21372ea1ccbfa8

Contents?: true

Size: 1.47 KB

Versions: 4

Compression:

Stored size: 1.47 KB

Contents

#include "RubySourceSupport.h"

#include "rb_Kernel.h"
#include "RPSender_internal.h"

#include "iseq.h"

//	Taken from eval.c in Ruby source
//	No header, so easiest way to integrate was to copy the code and make my own header.
//	Previously declared static; otherwise unchanged

ID frame_func_id( rb_control_frame_t *cfp )
{
    rb_iseq_t *iseq = cfp->iseq;
    if (!iseq) {
		return cfp->method_id;
    }
    while (iseq) {
		
		if (RUBY_VM_IFUNC_P(iseq)) {
			return rb_intern("<ifunc>");
		}
		if (iseq->defined_method_id) {
			return iseq->defined_method_id;
		}
		if (iseq->local_iseq == iseq) {
			break;
		}
		iseq = iseq->parent_iseq;
    }
    return 0;
}

ID rb_frame_caller(void)
{
    rb_thread_t *th = GET_THREAD();
    rb_control_frame_t *prev_cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(th->cfp);
    /* check if prev_cfp can be accessible */
    if ((void *)(th->stack + th->stack_size) == (void *)(prev_cfp)) {
        return 0;
    }
    return frame_func_id(prev_cfp);
}

int rb_vm_get_sourceline(const rb_control_frame_t *cfp)
{
    int line_no = 0;
    const rb_iseq_t *iseq = cfp->iseq;
	
    if (RUBY_VM_NORMAL_ISEQ_P(iseq)) {
		rb_num_t i;
		size_t pos = cfp->pc - cfp->iseq->iseq_encoded;
		
		for (i = 0; i < iseq->insn_info_size; i++) {
			if (iseq->insn_info_table[i].position == pos) {
				if (i == 0) goto found;
				line_no = iseq->insn_info_table[i - 1].line_no;
				goto found;
			}
		}
		line_no = iseq->insn_info_table[i - 1].line_no;
    }
found:
    return line_no;
}









Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
sender-1.4.3 ext/sender/RubySourceSupport.c
sender-1.4.2 ext/sender/RubySourceSupport.c
sender-1.4.1 ext/sender/RubySourceSupport.c
sender-1.4 ext/sender/RubySourceSupport.c