Issue #5249 has been updated by Koichi Sasada.

Status changed from Open to Assigned
Assignee set to Koichi Sasada


----------------------------------------
Bug #5249: C ??? Proc ????????????
https://bugs.ruby-lang.org/issues/5249

Author: Anonymous
Status: Assigned
Priority: Normal
Assignee: Koichi Sasada
Category: core
Target version: 
ruby -v: ruby 1.9.3dev (2011-08-02 revision 32810) [i686-linux]


???????????????

Proc#eq(C ?????? proc.c ?????? proc_eq)????C ????義????? Proc
(rb_proc_new ??????????????)????????????????????????????????????????
C ????義????? Proc ??対??????? iseq ?????????????????????????????????????
?????? segv ??????????????? false ???????? true ???????????????????

???????? proc_eq ??以???????????????????Proc ??種???????????????????
proc->block.iseq->iseq_size, proc->block.iseq->local_size,
proc->block.iseq->iseq ??????????????????????????
proc->block.iseq ??? IFUNC_NODE ????????????????????????????????????
????????????????????????????

/* ???????? */
static VALUE
proc_eq(VALUE self, VALUE other)
{
  if (self == other) {
    return Qtrue;
  }
  else {
    if (rb_obj_is_proc(other)) {
      rb_proc_t *p1, *p2;
      GetProcPtr(self, p1);
      GetProcPtr(other, p2);
      if (p1->envval == p2->envval &&
        p1->block.iseq->iseq_size == p2->block.iseq->iseq_size &&
        p1->block.iseq->local_size == p2->block.iseq->local_size &&
        MEMCMP(p1->block.iseq->iseq, p2->block.iseq->iseq, VALUE,
               p1->block.iseq->iseq_size) == 0) {
        return Qtrue;
      }
    }
  }
  return Qfalse;
}

添???????? sample.zip ????proc_eq ??対???????????????????????????????????????
???????????????????????
???????????????????RUBY_VM_IFUNC_P ??? C ??? Proc ???????????????????????proc ?
???????? C ??? Proc ???????????????node->nd_cfnc,  node->nd_aid,
node->nd_tval ???????????????

????????????????????????????幸??????????
??????????????????????????????????



/* ????????? */
diff --git proc.c proc.c
index 427d1fe..e304295 100644
--- proc.c
+++ proc.c
@@ -766,7 +766,18 @@ proc_eq(VALUE self, VALUE other)
            rb_proc_t *p1, *p2;
            GetProcPtr(self, p1);
            GetProcPtr(other, p2);
-           if (p1->envval == p2->envval &&
+           if (RUBY_VM_IFUNC_P(p1->block.iseq) &&
RUBY_VM_IFUNC_P(p2->block.iseq)) {
+               NODE *nd_ifunc1, *nd_ifunc2;
+
+               nd_ifunc1 = (NODE *)p1->block.iseq;
+               nd_ifunc2 = (NODE *)p2->block.iseq;
+               if(nd_ifunc1->nd_cfnc == nd_ifunc2->nd_cfnc &&
+                  nd_ifunc1->nd_aid == nd_ifunc2->nd_aid &&
+                  rb_funcall(nd_ifunc1->nd_tval, idEq, 1,
nd_ifunc2->nd_tval)) {
+                   return Qtrue;
+               }
+           } else if (p1->envval == p2->envval &&
+               !RUBY_VM_IFUNC_P(p1->block.iseq) &&
!RUBY_VM_IFUNC_P(p2->block.iseq) &&
                p1->block.iseq->iseq_size == p2->block.iseq->iseq_size &&
                p1->block.iseq->local_size == p2->block.iseq->local_size &&
                MEMCMP(p1->block.iseq->iseq, p2->block.iseq->iseq, VALUE,


-- 
http://bugs.ruby-lang.org/