Project

General

Profile

Feature #3905 ยป 0001-error.c-rb_mod_sys_fail-use-subclass-and-cache.patch

normalperson (Eric Wong), 10/05/2010 06:56 AM

View differences:

error.c
27 27

  
28 28
extern const char ruby_description[];
29 29

  
30
static VALUE mod_sys_fail_cache;
31

  
30 32
static const char *
31 33
rb_strerrno(int err)
32 34
{
......
1541 1543
void
1542 1544
rb_mod_sys_fail(VALUE mod, const char *mesg)
1543 1545
{
1544
    VALUE exc = make_errno_exc(mesg);
1545
    rb_extend_object(exc, mod);
1546
    int n = errno;
1547
    int need_aset_tmp = 0;
1548
    VALUE super_class;
1549
    VALUE cached_class;
1550
    VALUE per_class;
1551
    VALUE exc;
1552
    VALUE arg;
1553

  
1554
    errno = 0;
1555
    if (n == 0) {
1556
	rb_bug("rb_mod_sys_fail(%s) - errno == 0", mesg ? mesg : "");
1557
    }
1558
    super_class = get_syserr(n);
1559

  
1560
    if (! mod_sys_fail_cache) {
1561
	mod_sys_fail_cache = rb_hash_new();
1562
	rb_global_variable(&mod_sys_fail_cache);
1563
    }
1564
    per_class = rb_hash_aref(mod_sys_fail_cache, super_class);
1565

  
1566
    if (NIL_P(per_class)) {
1567
	need_aset_tmp = 1;
1568
	per_class = rb_hash_new();
1569
    }
1570

  
1571
    cached_class = rb_hash_aref(per_class, mod);
1572
    if (NIL_P(cached_class)) {
1573
	cached_class = rb_obj_dup(super_class);
1574
	rb_include_module(cached_class, mod);
1575
	rb_hash_aset(per_class, mod, cached_class);
1576
	if (need_aset_tmp)
1577
	    rb_hash_aset(mod_sys_fail_cache, super_class, per_class);
1578
    }
1579

  
1580
    arg = mesg ? rb_str_new2(mesg) : Qnil;
1581
    exc = rb_class_new_instance(1, &arg, cached_class);
1546 1582
    rb_exc_raise(exc);
1547 1583
}
1548 1584

  
1549
-