mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
calc_lineno(): add assertions
This function has a lot of assumptions. Should make them sure.
This commit is contained in:
parent
5d33f78716
commit
19d3c80e81
2 changed files with 29 additions and 12 deletions
2
vm.c
2
vm.c
|
@ -1343,7 +1343,7 @@ rb_source_location(int *pline)
|
||||||
const rb_execution_context_t *ec = GET_EC();
|
const rb_execution_context_t *ec = GET_EC();
|
||||||
const rb_control_frame_t *cfp = rb_vm_get_ruby_level_next_cfp(ec, ec->cfp);
|
const rb_control_frame_t *cfp = rb_vm_get_ruby_level_next_cfp(ec, ec->cfp);
|
||||||
|
|
||||||
if (cfp && cfp->iseq) {
|
if (cfp && VM_FRAME_RUBYFRAME_P(cfp)) {
|
||||||
if (pline) *pline = rb_vm_get_sourceline(cfp);
|
if (pline) *pline = rb_vm_get_sourceline(cfp);
|
||||||
return rb_iseq_path(cfp->iseq);
|
return rb_iseq_path(cfp->iseq);
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,23 @@ id2str(ID id)
|
||||||
inline static int
|
inline static int
|
||||||
calc_lineno(const rb_iseq_t *iseq, const VALUE *pc)
|
calc_lineno(const rb_iseq_t *iseq, const VALUE *pc)
|
||||||
{
|
{
|
||||||
size_t pos = (size_t)(pc - iseq->body->iseq_encoded);
|
VM_ASSERT(iseq);
|
||||||
|
VM_ASSERT(iseq->body);
|
||||||
|
VM_ASSERT(iseq->body->iseq_encoded);
|
||||||
|
VM_ASSERT(iseq->body->iseq_size);
|
||||||
|
if (! pc) {
|
||||||
|
/* This can happen during VM bootup. */
|
||||||
|
VM_ASSERT(iseq->body->type == ISEQ_TYPE_TOP);
|
||||||
|
VM_ASSERT(! iseq->body->local_table);
|
||||||
|
VM_ASSERT(! iseq->body->local_table_size);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ptrdiff_t n = pc - iseq->body->iseq_encoded;
|
||||||
|
VM_ASSERT(n <= iseq->body->iseq_size);
|
||||||
|
VM_ASSERT(n >= 0);
|
||||||
|
ASSUME(n >= 0);
|
||||||
|
size_t pos = n; /* no overflow */
|
||||||
if (LIKELY(pos)) {
|
if (LIKELY(pos)) {
|
||||||
/* use pos-1 because PC points next instruction at the beginning of instruction */
|
/* use pos-1 because PC points next instruction at the beginning of instruction */
|
||||||
pos--;
|
pos--;
|
||||||
|
@ -46,6 +62,7 @@ calc_lineno(const rb_iseq_t *iseq, const VALUE *pc)
|
||||||
#endif
|
#endif
|
||||||
return rb_iseq_line_no(iseq, pos);
|
return rb_iseq_line_no(iseq, pos);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
rb_vm_get_sourceline(const rb_control_frame_t *cfp)
|
rb_vm_get_sourceline(const rb_control_frame_t *cfp)
|
||||||
|
@ -1296,7 +1313,7 @@ rb_profile_frames(int start, int limit, VALUE *buff, int *lines)
|
||||||
const rb_callable_method_entry_t *cme;
|
const rb_callable_method_entry_t *cme;
|
||||||
|
|
||||||
for (i=0; i<limit && cfp != end_cfp;) {
|
for (i=0; i<limit && cfp != end_cfp;) {
|
||||||
if (cfp->iseq && cfp->pc) {
|
if (VM_FRAME_RUBYFRAME_P(cfp)) {
|
||||||
if (start > 0) {
|
if (start > 0) {
|
||||||
start--;
|
start--;
|
||||||
continue;
|
continue;
|
||||||
|
|
Loading…
Add table
Reference in a new issue