const_missing_murphy.patch

another patch for NoConstantError behavior - Kornelius Kalnbach, 02/16/2010 11:53 AM

Download (2.56 KB)

View differences:

error.c (working copy)
402 402
VALUE rb_eLoadError;
403 403

  
404
VALUE rb_eNoConstantError;
405

  
404 406
VALUE rb_eSystemCallError;
405 407
VALUE rb_mErrno;
......
1143 1145
    rb_define_method(rb_eNoMethodError, "initialize", nometh_err_initialize, -1);
1144 1146
    rb_define_method(rb_eNoMethodError, "args", nometh_err_args, 0);
1147
    rb_eNoConstantError = rb_define_class("NoConstantError", rb_eNameError);
1145 1148

  
1146 1149
    rb_eRuntimeError = rb_define_class("RuntimeError", rb_eStandardError);
variable.c (working copy)
1355 1355
}
1356 1356

  
1357 1357
static VALUE
1358
const_missing_call(VALUE arg)
1359
{
1360
    VALUE *args = (VALUE *)arg;
1361
    ID const_missing_id;
1362
    CONST_ID(const_missing_id, "const_missing");
1363
    return rb_check_funcall(args[0], const_missing_id, 1, &args[1]);
1364
}
1365

  
1366
static VALUE
1367
const_missing_rescue(VALUE arg, VALUE errinfo)
1368
{
1369
    return arg;
1370
}
1371

  
1372
extern VALUE rb_eNoConstantError;
1373

  
1374
static VALUE
1358 1375
const_missing(VALUE klass, ID id)
1359 1376
{
1360
    return rb_funcall(klass, rb_intern("const_missing"), 1, ID2SYM(id));
1377
    VALUE args[2];
1378
    args[0] = klass;
1379
    args[1] = ID2SYM(id);
1380
    return rb_rescue2(const_missing_call, (VALUE)args,
1381
		      const_missing_rescue, (VALUE)Qundef,
1382
		      rb_eNoConstantError, (VALUE)0);
1361 1383
}
1362 1384

  
1363 1385

  
......
1392 1414
VALUE
1393 1415
rb_mod_const_missing(VALUE klass, VALUE name)
1394 1416
{
1395
    rb_frame_pop(); /* pop frame for "const_missing" */
1396
    uninitialized_constant(klass, rb_to_id(name));
1417
    rb_raise(rb_eNoConstantError, "uninitialized constant");
1397 1418
    return Qnil;		/* not reached */
1398 1419
}
1399 1420

  
......
1596 1617
	tmp = rb_cObject;
1597 1618
	goto retry;
1598 1619
    }
1620
    
1621
    tmp = klass;
1622
    if ((value = const_missing(tmp, id)) == Qundef) {
1623
	NODE *rb_vm_cref(void);
1624
	NODE *cref = rb_vm_cref();
1625
        cref = cref->nd_next;
1626
        while (cref && cref->nd_next &&
1627
               ((cref->flags & NODE_FL_CREF_PUSHED_BY_EVAL) ||
1628
             NIL_P(tmp = cref->nd_clss) ||
1629
             (value = const_missing(tmp, id)) == Qundef)) {
1630
            cref = cref->nd_next;
1631
        }
1632
	if (value == Qundef) {
1633
	    if (!exclude && (BUILTIN_TYPE(klass) == T_MODULE || BUILTIN_TYPE(klass) == T_CLASS) &&
1634
		(value = const_missing(rb_cObject, id)) == Qundef) {
1635
		uninitialized_constant(klass, id);
1636
	    }
1637
	}
1638
    }
1599 1639

  
1600
    value = const_missing(klass, id);
1601 1640
    rb_vm_inc_const_missing_count();
1602 1641
    return value;
1603 1642
}