mirror of
				https://github.com/ruby/ruby.git
				synced 2022-11-09 12:17:21 -05:00 
			
		
		
		
	* array.c (rb_values_at): extract common procedure from
rb_ary_values_at. follow DRY principle. * re.c (match_values_at): values_at should understand ranges. * struct.c (rb_struct_values_at): ditto. * struct.c (inspect_struct): inspect format changed; add "struct " at the top. * sprintf.c (rb_f_sprintf): "%p" specifier for inspect output. (RCR#68) * eval.c (rb_mod_undef_method): allow "undef_method" to accept multiple arguments. (RCR#146) * lib/timeout.rb: put timeout in Timeout module. (RCR#121) [ruby-talk:61028] * re.c (match_groups): new method added. (RCR#139) * variable.c (rb_mod_const_of): should exclude constant defined in Object, unless retrieving constants of Object. * string.c (rb_str_new4): do not allocate new string if original is frozen or already have copy-on-write entry. [ruby-talk:74940] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4031 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
		
							parent
							
								
									a11ab83884
								
							
						
					
					
						commit
						9d22a06ea0
					
				
					 13 changed files with 157 additions and 96 deletions
				
			
		
							
								
								
									
										33
									
								
								ChangeLog
									
										
									
									
									
								
							
							
						
						
									
										33
									
								
								ChangeLog
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -1,10 +1,43 @@
 | 
			
		|||
Thu Jul  3 14:22:46 2003  Yukihiro Matsumoto  <matz@ruby-lang.org>
 | 
			
		||||
 | 
			
		||||
	* array.c (rb_values_at): extract common procedure from
 | 
			
		||||
	  rb_ary_values_at.  follow DRY principle.
 | 
			
		||||
 | 
			
		||||
	* re.c (match_values_at): values_at should understand ranges.
 | 
			
		||||
 | 
			
		||||
	* struct.c (rb_struct_values_at): ditto.
 | 
			
		||||
 | 
			
		||||
	* struct.c (inspect_struct): inspect format changed; add "struct "
 | 
			
		||||
	  at the top.
 | 
			
		||||
 | 
			
		||||
	* sprintf.c (rb_f_sprintf): "%p" specifier for inspect output.
 | 
			
		||||
	  (RCR#68)
 | 
			
		||||
 | 
			
		||||
	* eval.c (rb_mod_undef_method): allow "undef_method" to accept
 | 
			
		||||
	  multiple arguments. (RCR#146)
 | 
			
		||||
 | 
			
		||||
	* lib/timeout.rb: put timeout in Timeout module. (RCR#121)
 | 
			
		||||
	  [ruby-talk:61028]
 | 
			
		||||
 | 
			
		||||
	* re.c (match_groups): new method added. (RCR#139)
 | 
			
		||||
 | 
			
		||||
	* variable.c (rb_mod_const_of): should exclude constant defined
 | 
			
		||||
	  in Object, unless retrieving constants of Object.
 | 
			
		||||
 | 
			
		||||
Thu Jul  3 12:13:05 2003  WATANABE Hirofumi  <eban@ruby-lang.org>
 | 
			
		||||
 | 
			
		||||
	* lib/mkmf.rb (VPATH): convert from Windows form to Unix form on 
 | 
			
		||||
	  MinGW.  This fixes the build with GNU make 3.80-1 for Cygwin.
 | 
			
		||||
 | 
			
		||||
Wed Jul  2 23:27:34 2003  Yukihiro Matsumoto  <matz@ruby-lang.org>
 | 
			
		||||
 | 
			
		||||
	* string.c (rb_str_new4): do not allocate new string if original
 | 
			
		||||
	  is frozen or already have copy-on-write entry. [ruby-talk:74940]
 | 
			
		||||
 | 
			
		||||
Wed Jul  2 13:22:39 2003  Yukihiro Matsumoto  <matz@ruby-lang.org>
 | 
			
		||||
 | 
			
		||||
	* string.c (rb_str_new4): 
 | 
			
		||||
 | 
			
		||||
	* string.c (rb_str_shared_replace): clear flags before copy.
 | 
			
		||||
 | 
			
		||||
	* string.c (rb_str_replace): ditto.
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										54
									
								
								array.c
									
										
									
									
									
								
							
							
						
						
									
										54
									
								
								array.c
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -1218,29 +1218,37 @@ rb_ary_collect_bang(ary)
 | 
			
		|||
    return ary;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
push_values_at(result, ary, arg)
 | 
			
		||||
    VALUE result, ary, arg;
 | 
			
		||||
VALUE
 | 
			
		||||
rb_values_at(obj, olen, argc, argv, func)
 | 
			
		||||
    VALUE obj;
 | 
			
		||||
    long olen;
 | 
			
		||||
    int argc;
 | 
			
		||||
    VALUE *argv;
 | 
			
		||||
    VALUE (*func) _((VALUE,long));
 | 
			
		||||
{
 | 
			
		||||
    long beg, len, i;
 | 
			
		||||
    VALUE result = rb_ary_new2(argc);
 | 
			
		||||
    long beg, len, i, j;
 | 
			
		||||
 | 
			
		||||
    if (FIXNUM_P(arg)) {
 | 
			
		||||
	rb_ary_push(result, rb_ary_entry(ary, FIX2LONG(arg)));
 | 
			
		||||
	return;
 | 
			
		||||
    }
 | 
			
		||||
    /* check if idx is Range */
 | 
			
		||||
    switch (rb_range_beg_len(arg, &beg, &len, RARRAY(ary)->len, 0)) {
 | 
			
		||||
      case Qfalse:
 | 
			
		||||
	break;
 | 
			
		||||
      case Qnil:
 | 
			
		||||
	return;
 | 
			
		||||
      default:
 | 
			
		||||
	for (i=0; i<len; i++) {
 | 
			
		||||
	    rb_ary_push(result, rb_ary_entry(ary, i+beg));
 | 
			
		||||
    for (i=0; i<argc; i++) {
 | 
			
		||||
	if (FIXNUM_P(argv[i])) {
 | 
			
		||||
	    rb_ary_push(result, (*func)(obj, FIX2LONG(argv[i])));
 | 
			
		||||
	    continue;
 | 
			
		||||
	}
 | 
			
		||||
	return;
 | 
			
		||||
	/* check if idx is Range */
 | 
			
		||||
	switch (rb_range_beg_len(argv[i], &beg, &len, olen, 0)) {
 | 
			
		||||
	  case Qfalse:
 | 
			
		||||
	    break;
 | 
			
		||||
	  case Qnil:
 | 
			
		||||
	    continue;
 | 
			
		||||
	  default:
 | 
			
		||||
	    for (j=0; j<len; j++) {
 | 
			
		||||
		rb_ary_push(result, (*func)(obj, j+beg));
 | 
			
		||||
	    }
 | 
			
		||||
	    continue;
 | 
			
		||||
	}
 | 
			
		||||
	rb_ary_push(result, (*func)(obj, NUM2LONG(argv[i])));
 | 
			
		||||
    }
 | 
			
		||||
    rb_ary_push(result, rb_ary_entry(ary, NUM2LONG(arg)));
 | 
			
		||||
    return result;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static VALUE
 | 
			
		||||
| 
						 | 
				
			
			@ -1249,13 +1257,7 @@ rb_ary_values_at(argc, argv, ary)
 | 
			
		|||
    VALUE *argv;
 | 
			
		||||
    VALUE ary;
 | 
			
		||||
{
 | 
			
		||||
    VALUE result = rb_ary_new2(argc);
 | 
			
		||||
    long i;
 | 
			
		||||
 | 
			
		||||
    for (i=0; i<argc; i++) {
 | 
			
		||||
	push_values_at(result, ary, argv[i]);
 | 
			
		||||
    }
 | 
			
		||||
    return result;
 | 
			
		||||
    return rb_values_at(ary, RARRAY(ary)->len, argc, argv, rb_ary_entry);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static VALUE
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										15
									
								
								eval.c
									
										
									
									
									
								
							
							
						
						
									
										15
									
								
								eval.c
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -362,6 +362,7 @@ rb_get_method_body(klassp, idp, noexp)
 | 
			
		|||
	    body = ent->method = body->nd_head;
 | 
			
		||||
	}
 | 
			
		||||
	else {
 | 
			
		||||
	    if (BUILTIN_TYPE(origin) == T_ICLASS) origin = RBASIC(origin)->klass;
 | 
			
		||||
	    *klassp = origin;
 | 
			
		||||
	    ent->origin = origin;
 | 
			
		||||
	    ent->mid = ent->mid0 = id;
 | 
			
		||||
| 
						 | 
				
			
			@ -1824,10 +1825,16 @@ rb_undef(klass, id)
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
static VALUE
 | 
			
		||||
rb_mod_undef_method(mod, name)
 | 
			
		||||
    VALUE mod, name;
 | 
			
		||||
rb_mod_undef_method(argc, argv, mod)
 | 
			
		||||
    int argc;
 | 
			
		||||
    VALUE *argv;
 | 
			
		||||
    VALUE mod;
 | 
			
		||||
{
 | 
			
		||||
    rb_undef(mod, rb_to_id(name));
 | 
			
		||||
    int i;
 | 
			
		||||
 | 
			
		||||
    for (i=0; i<argc; i++) {
 | 
			
		||||
	rb_undef(mod, rb_to_id(argv[i]));
 | 
			
		||||
    }
 | 
			
		||||
    return mod;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -6521,7 +6528,7 @@ Init_eval()
 | 
			
		|||
    rb_undef_method(rb_cClass, "module_function");
 | 
			
		||||
 | 
			
		||||
    rb_define_private_method(rb_cModule, "remove_method", rb_mod_remove_method, 1);
 | 
			
		||||
    rb_define_private_method(rb_cModule, "undef_method", rb_mod_undef_method, 1);
 | 
			
		||||
    rb_define_private_method(rb_cModule, "undef_method", rb_mod_undef_method, -1);
 | 
			
		||||
    rb_define_private_method(rb_cModule, "alias_method", rb_mod_alias_method, 2);
 | 
			
		||||
    rb_define_private_method(rb_cModule, "define_method", rb_mod_define_method, -1);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										1
									
								
								intern.h
									
										
									
									
									
								
							
							
						
						
									
										1
									
								
								intern.h
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -56,6 +56,7 @@ VALUE rb_ary_cmp _((VALUE, VALUE));
 | 
			
		|||
VALUE rb_protect_inspect _((VALUE(*)(ANYARGS),VALUE,VALUE));
 | 
			
		||||
VALUE rb_inspecting_p _((VALUE));
 | 
			
		||||
VALUE rb_check_array_value _((VALUE));
 | 
			
		||||
VALUE rb_values_at _((VALUE, long, int, VALUE*, VALUE(*) _((VALUE,long))));
 | 
			
		||||
/* bignum.c */
 | 
			
		||||
VALUE rb_big_clone _((VALUE));
 | 
			
		||||
void rb_big_2comp _((VALUE));
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -700,9 +700,11 @@ EOHELP
 | 
			
		|||
    @line = line
 | 
			
		||||
    case event
 | 
			
		||||
    when 'line'
 | 
			
		||||
      p [line, @stop_next]
 | 
			
		||||
      frame_set_pos(file, line)
 | 
			
		||||
      if !@no_step or @frames.size == @no_step
 | 
			
		||||
	@stop_next -= 1
 | 
			
		||||
	@stop_next = 0 if @stop_next < 0
 | 
			
		||||
      elsif @frames.size < @no_step
 | 
			
		||||
	@stop_next = 0		# break here before leaving...
 | 
			
		||||
      else
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -177,6 +177,7 @@ module IRB
 | 
			
		|||
      @inspect_mode
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    undef use_readline=
 | 
			
		||||
    def use_readline=(opt)
 | 
			
		||||
      @use_readline = opt
 | 
			
		||||
      print "use readline module\n" if @use_readline
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -8,6 +8,7 @@ CONFIG = Config::MAKEFILE_CONFIG
 | 
			
		|||
ORIG_LIBPATH = ENV['LIB']
 | 
			
		||||
 | 
			
		||||
SRC_EXT = ["c", "cc", "m", "cxx", "cpp", "C"]
 | 
			
		||||
$static = $config_h = nil
 | 
			
		||||
 | 
			
		||||
unless defined? $configure_args
 | 
			
		||||
  $configure_args = {}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -23,25 +23,38 @@
 | 
			
		|||
#
 | 
			
		||||
#    The time in seconds to wait for block teminatation.   
 | 
			
		||||
#
 | 
			
		||||
#  : [exception]
 | 
			
		||||
#
 | 
			
		||||
#    The exception classs to be raised on timeout.
 | 
			
		||||
#
 | 
			
		||||
#=end
 | 
			
		||||
 | 
			
		||||
class TimeoutError<Interrupt
 | 
			
		||||
module Timeout
 | 
			
		||||
  class Error<Interrupt
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def timeout(sec, exception=Error)
 | 
			
		||||
    return yield if sec == nil
 | 
			
		||||
    begin
 | 
			
		||||
      x = Thread.current
 | 
			
		||||
      y = Thread.start {
 | 
			
		||||
        sleep sec
 | 
			
		||||
        x.raise exception, "execution expired" if x.alive?
 | 
			
		||||
      }
 | 
			
		||||
      yield sec
 | 
			
		||||
      #    return true
 | 
			
		||||
    ensure
 | 
			
		||||
      y.kill if y and y.alive?
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
  module_function :timeout
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
def timeout(sec, exception=TimeoutError)
 | 
			
		||||
  return yield if sec == nil
 | 
			
		||||
  begin
 | 
			
		||||
    x = Thread.current
 | 
			
		||||
    y = Thread.start {
 | 
			
		||||
      sleep sec
 | 
			
		||||
      x.raise exception, "execution expired" if x.alive?
 | 
			
		||||
    }
 | 
			
		||||
    yield sec
 | 
			
		||||
#    return true
 | 
			
		||||
  ensure
 | 
			
		||||
    y.kill if y and y.alive?
 | 
			
		||||
  end
 | 
			
		||||
# compatible
 | 
			
		||||
def timeout(n, &block)
 | 
			
		||||
  Timeout::timeout(n, &block)
 | 
			
		||||
end
 | 
			
		||||
TimeoutError = Timeout::Error
 | 
			
		||||
 | 
			
		||||
if __FILE__ == $0
 | 
			
		||||
  p timeout(5) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										49
									
								
								re.c
									
										
									
									
									
								
							
							
						
						
									
										49
									
								
								re.c
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -914,8 +914,9 @@ last_paren_match_getter()
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
static VALUE
 | 
			
		||||
match_to_a(match)
 | 
			
		||||
match_array(match, start)
 | 
			
		||||
    VALUE match;
 | 
			
		||||
    int start;
 | 
			
		||||
{
 | 
			
		||||
    struct re_registers *regs = RMATCH(match)->regs;
 | 
			
		||||
    VALUE ary = rb_ary_new2(regs->num_regs);
 | 
			
		||||
| 
						 | 
				
			
			@ -923,7 +924,7 @@ match_to_a(match)
 | 
			
		|||
    int i;
 | 
			
		||||
    int taint = OBJ_TAINTED(match);
 | 
			
		||||
    
 | 
			
		||||
    for (i=0; i<regs->num_regs; i++) {
 | 
			
		||||
    for (i=start; i<regs->num_regs; i++) {
 | 
			
		||||
	if (regs->beg[i] == -1) {
 | 
			
		||||
	    rb_ary_push(ary, Qnil);
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			@ -936,6 +937,20 @@ match_to_a(match)
 | 
			
		|||
    return ary;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static VALUE
 | 
			
		||||
match_to_a(match)
 | 
			
		||||
    VALUE match;
 | 
			
		||||
{
 | 
			
		||||
    return match_array(match, 0);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static VALUE
 | 
			
		||||
match_groups(match)
 | 
			
		||||
    VALUE match;
 | 
			
		||||
{
 | 
			
		||||
    return match_array(match, 1);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static VALUE
 | 
			
		||||
match_aref(argc, argv, match)
 | 
			
		||||
    int argc;
 | 
			
		||||
| 
						 | 
				
			
			@ -952,32 +967,21 @@ match_aref(argc, argv, match)
 | 
			
		|||
    return rb_reg_nth_match(FIX2INT(idx), match);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static VALUE
 | 
			
		||||
match_entry(match, n)
 | 
			
		||||
    VALUE match;
 | 
			
		||||
    long n;
 | 
			
		||||
{
 | 
			
		||||
    return rb_reg_nth_match(n, match);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static VALUE
 | 
			
		||||
match_values_at(argc, argv, match)
 | 
			
		||||
    int argc;
 | 
			
		||||
    VALUE *argv;
 | 
			
		||||
    VALUE match;
 | 
			
		||||
{
 | 
			
		||||
    struct re_registers *regs = RMATCH(match)->regs;
 | 
			
		||||
    VALUE target = RMATCH(match)->str;
 | 
			
		||||
    VALUE result = rb_ary_new();
 | 
			
		||||
    int i;
 | 
			
		||||
    long idx;
 | 
			
		||||
    int taint = OBJ_TAINTED(match);
 | 
			
		||||
 | 
			
		||||
    for (i=0; i<argc; i++) {
 | 
			
		||||
	idx = NUM2LONG(argv[i]);
 | 
			
		||||
	if (idx < 0) idx += regs->num_regs;
 | 
			
		||||
	if (idx < 0 || regs->num_regs <= idx) {
 | 
			
		||||
	    rb_ary_push(result, Qnil);
 | 
			
		||||
	}
 | 
			
		||||
	else {
 | 
			
		||||
	    VALUE str = rb_str_substr(target, regs->beg[idx], regs->end[idx]-regs->beg[idx]);
 | 
			
		||||
	    if (taint) OBJ_TAINT(str);
 | 
			
		||||
	    rb_ary_push(result, str);
 | 
			
		||||
	}
 | 
			
		||||
    }
 | 
			
		||||
    return result;
 | 
			
		||||
    return rb_values_at(match, RMATCH(match)->regs->num_regs, argc, argv, match_entry);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static VALUE
 | 
			
		||||
| 
						 | 
				
			
			@ -1766,6 +1770,7 @@ Init_Regexp()
 | 
			
		|||
    rb_define_method(rb_cMatch, "end", match_end, 1);
 | 
			
		||||
    rb_define_method(rb_cMatch, "to_a", match_to_a, 0);
 | 
			
		||||
    rb_define_method(rb_cMatch, "[]", match_aref, -1);
 | 
			
		||||
    rb_define_method(rb_cMatch, "groups", match_groups, 0);
 | 
			
		||||
    rb_define_method(rb_cMatch, "select", match_select, -1);
 | 
			
		||||
    rb_define_method(rb_cMatch, "values_at", match_values_at, -1);
 | 
			
		||||
    rb_define_method(rb_cMatch, "pre_match", rb_reg_match_pre, 0);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -291,10 +291,12 @@ rb_f_sprintf(argc, argv)
 | 
			
		|||
	    break;
 | 
			
		||||
 | 
			
		||||
	  case 's':
 | 
			
		||||
	  case 'p':
 | 
			
		||||
	    {
 | 
			
		||||
		VALUE arg = GETARG();
 | 
			
		||||
		long len;
 | 
			
		||||
 | 
			
		||||
		if (*p == 'p') arg = rb_inspect(arg);
 | 
			
		||||
		str = rb_obj_as_string(arg);
 | 
			
		||||
		if (OBJ_TAINTED(str)) tainted = 1;
 | 
			
		||||
		len = RSTRING(str)->len;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										9
									
								
								string.c
									
										
									
									
									
								
							
							
						
						
									
										9
									
								
								string.c
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -157,14 +157,17 @@ rb_str_new4(orig)
 | 
			
		|||
{
 | 
			
		||||
    VALUE klass, str;
 | 
			
		||||
 | 
			
		||||
    if (OBJ_FROZEN(orig)) return orig;
 | 
			
		||||
    klass = rb_obj_class(orig);
 | 
			
		||||
    if (FL_TEST(orig, ELTS_SHARED) && RSTRING(orig)->aux.shared) {
 | 
			
		||||
	long ofs;
 | 
			
		||||
	str = RSTRING(orig)->aux.shared;
 | 
			
		||||
	ofs = RSTRING(str)->len - RSTRING(orig)->len;
 | 
			
		||||
	str = str_new3(klass, str);
 | 
			
		||||
	RSTRING(str)->ptr += ofs;
 | 
			
		||||
	RSTRING(str)->len -= ofs;
 | 
			
		||||
	if (ofs > 0) {
 | 
			
		||||
	    str = str_new3(klass, str);
 | 
			
		||||
	    RSTRING(str)->ptr += ofs;
 | 
			
		||||
	    RSTRING(str)->len -= ofs;
 | 
			
		||||
	}
 | 
			
		||||
    }
 | 
			
		||||
    else if (FL_TEST(orig, STR_ASSOC)) {
 | 
			
		||||
	str = str_new(klass, RSTRING(orig)->ptr, RSTRING(orig)->len);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										37
									
								
								struct.c
									
										
									
									
									
								
							
							
						
						
									
										37
									
								
								struct.c
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -351,18 +351,6 @@ rb_struct_each_pair(s)
 | 
			
		|||
    return s;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static VALUE
 | 
			
		||||
rb_struct_to_s(s)
 | 
			
		||||
    VALUE s;
 | 
			
		||||
{
 | 
			
		||||
    char *cname = rb_class2name(rb_obj_class(s));
 | 
			
		||||
    VALUE str = rb_str_new(0, strlen(cname) + 4);
 | 
			
		||||
 | 
			
		||||
    sprintf(RSTRING(str)->ptr, "#<%s>", cname);
 | 
			
		||||
    RSTRING(str)->len = strlen(RSTRING(str)->ptr);
 | 
			
		||||
    return str;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static VALUE
 | 
			
		||||
inspect_struct(s)
 | 
			
		||||
    VALUE s;
 | 
			
		||||
| 
						 | 
				
			
			@ -376,7 +364,7 @@ inspect_struct(s)
 | 
			
		|||
	rb_bug("non-initialized struct");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    str = rb_str_buf_new2("#<");
 | 
			
		||||
    str = rb_str_buf_new2("#<struct ");
 | 
			
		||||
    rb_str_cat2(str, cname);
 | 
			
		||||
    rb_str_cat2(str, " ");
 | 
			
		||||
    for (i=0; i<RSTRUCT(s)->len; i++) {
 | 
			
		||||
| 
						 | 
				
			
			@ -405,9 +393,9 @@ rb_struct_inspect(s)
 | 
			
		|||
{
 | 
			
		||||
    if (rb_inspecting_p(s)) {
 | 
			
		||||
	char *cname = rb_class2name(rb_obj_class(s));
 | 
			
		||||
	VALUE str = rb_str_new(0, strlen(cname) + 8);
 | 
			
		||||
	VALUE str = rb_str_new(0, strlen(cname) + 15);
 | 
			
		||||
 | 
			
		||||
	sprintf(RSTRING(str)->ptr, "#<%s:...>", cname);
 | 
			
		||||
	sprintf(RSTRING(str)->ptr, "#<struct %s:...>", cname);
 | 
			
		||||
	RSTRING(str)->len = strlen(RSTRING(str)->ptr);
 | 
			
		||||
	return str;
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -529,20 +517,21 @@ rb_struct_aset(s, idx, val)
 | 
			
		|||
    return RSTRUCT(s)->ptr[i] = val;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static VALUE
 | 
			
		||||
struct_entry(s, n)
 | 
			
		||||
    VALUE s;
 | 
			
		||||
    long n;
 | 
			
		||||
{
 | 
			
		||||
    return rb_struct_aref(s, LONG2NUM(n));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static VALUE
 | 
			
		||||
rb_struct_values_at(argc, argv, s)
 | 
			
		||||
    int argc;
 | 
			
		||||
    VALUE *argv;
 | 
			
		||||
    VALUE s;
 | 
			
		||||
{
 | 
			
		||||
    VALUE result = rb_ary_new();
 | 
			
		||||
    long i;
 | 
			
		||||
 | 
			
		||||
    for (i=0; i<argc; i++) {
 | 
			
		||||
	rb_ary_push(result, rb_struct_aref(s, argv[i]));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return result;
 | 
			
		||||
    return rb_values_at(s, RSTRUCT(s)->len, argc, argv, struct_entry);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static VALUE
 | 
			
		||||
| 
						 | 
				
			
			@ -648,7 +637,7 @@ Init_Struct()
 | 
			
		|||
    rb_define_method(rb_cStruct, "eql?", rb_struct_eql, 1);
 | 
			
		||||
    rb_define_method(rb_cStruct, "hash", rb_struct_hash, 0);
 | 
			
		||||
 | 
			
		||||
    rb_define_method(rb_cStruct, "to_s", rb_struct_to_s, 0);
 | 
			
		||||
    rb_define_method(rb_cStruct, "to_s", rb_struct_inspect, 0);
 | 
			
		||||
    rb_define_method(rb_cStruct, "inspect", rb_struct_inspect, 0);
 | 
			
		||||
    rb_define_method(rb_cStruct, "to_a", rb_struct_to_a, 0);
 | 
			
		||||
    rb_define_method(rb_cStruct, "values", rb_struct_to_a, 0);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1387,10 +1387,12 @@ rb_mod_const_of(mod, data)
 | 
			
		|||
    VALUE mod;
 | 
			
		||||
    void *data;
 | 
			
		||||
{
 | 
			
		||||
    VALUE tmp = mod;
 | 
			
		||||
    for (;;) {
 | 
			
		||||
	data = rb_mod_const_at(mod, data);
 | 
			
		||||
	mod = RCLASS(mod)->super;
 | 
			
		||||
	if (!mod) break;
 | 
			
		||||
	data = rb_mod_const_at(tmp, data);
 | 
			
		||||
	tmp = RCLASS(tmp)->super;
 | 
			
		||||
	if (!tmp) break;
 | 
			
		||||
	if (tmp == rb_cObject && mod != rb_cObject) break;
 | 
			
		||||
    }
 | 
			
		||||
    return data;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue