mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* array.c (push_values_at): Array#values_at should work with
ranges too. * range.c (rb_range_beg_len): length calculation was wrong. * eval.c (rb_call): should set T_ICLASS in the frame->last_class. [ruby-core:01110] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3899 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
f5a7f85917
commit
6125313d69
12 changed files with 114 additions and 57 deletions
10
ChangeLog
10
ChangeLog
|
@ -1,3 +1,13 @@
|
||||||
|
Mon Jun 2 02:20:52 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||||
|
|
||||||
|
* array.c (push_values_at): Array#values_at should work with
|
||||||
|
ranges too.
|
||||||
|
|
||||||
|
* range.c (rb_range_beg_len): length calculation was wrong.
|
||||||
|
|
||||||
|
* eval.c (rb_call): should set T_ICLASS in the frame->last_class.
|
||||||
|
[ruby-core:01110]
|
||||||
|
|
||||||
Sun Jun 1 21:50:01 2003 WATANABE Hirofumi <eban@ruby-lang.org>
|
Sun Jun 1 21:50:01 2003 WATANABE Hirofumi <eban@ruby-lang.org>
|
||||||
|
|
||||||
* configure.in: should not use def file, use ld with
|
* configure.in: should not use def file, use ld with
|
||||||
|
|
27
array.c
27
array.c
|
@ -1179,6 +1179,31 @@ rb_ary_collect_bang(ary)
|
||||||
return ary;
|
return ary;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
push_values_at(result, ary, arg)
|
||||||
|
VALUE result, ary, arg;
|
||||||
|
{
|
||||||
|
long beg, len, i;
|
||||||
|
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
rb_ary_push(result, rb_ary_entry(ary, NUM2LONG(arg)));
|
||||||
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
rb_ary_values_at(argc, argv, ary)
|
rb_ary_values_at(argc, argv, ary)
|
||||||
int argc;
|
int argc;
|
||||||
|
@ -1189,7 +1214,7 @@ rb_ary_values_at(argc, argv, ary)
|
||||||
long i;
|
long i;
|
||||||
|
|
||||||
for (i=0; i<argc; i++) {
|
for (i=0; i<argc; i++) {
|
||||||
rb_ary_push(result, rb_ary_entry(ary, NUM2LONG(argv[i])));
|
push_values_at(result, ary, argv[i]);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
40
error.c
40
error.c
|
@ -26,6 +26,23 @@
|
||||||
|
|
||||||
int ruby_nerrs;
|
int ruby_nerrs;
|
||||||
|
|
||||||
|
static int
|
||||||
|
err_position(buf, len)
|
||||||
|
char *buf;
|
||||||
|
long len;
|
||||||
|
{
|
||||||
|
ruby_set_current_source();
|
||||||
|
if (!ruby_sourcefile) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else if (ruby_sourceline == 0) {
|
||||||
|
return snprintf(buf, len, "%s: ", ruby_sourcefile);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return snprintf(buf, len, "%s:%d: ", ruby_sourcefile, ruby_sourceline);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
err_snprintf(buf, len, fmt, args)
|
err_snprintf(buf, len, fmt, args)
|
||||||
char *buf;
|
char *buf;
|
||||||
|
@ -35,17 +52,7 @@ err_snprintf(buf, len, fmt, args)
|
||||||
{
|
{
|
||||||
long n;
|
long n;
|
||||||
|
|
||||||
ruby_set_current_source();
|
n = err_position(buf, len);
|
||||||
if (!ruby_sourcefile) {
|
|
||||||
vsnprintf(buf, len, fmt, args);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else if (ruby_sourceline == 0) {
|
|
||||||
n = snprintf(buf, len, "%s: ", ruby_sourcefile);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
n = snprintf(buf, len, "%s:%d: ", ruby_sourcefile, ruby_sourceline);
|
|
||||||
}
|
|
||||||
if (len > n) {
|
if (len > n) {
|
||||||
vsnprintf((char*)buf+n, len-n, fmt, args);
|
vsnprintf((char*)buf+n, len-n, fmt, args);
|
||||||
}
|
}
|
||||||
|
@ -151,6 +158,15 @@ rb_warning(fmt, va_alist)
|
||||||
va_end(args);
|
va_end(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static VALUE
|
||||||
|
rb_warn_m(self, mesg)
|
||||||
|
VALUE self, mesg;
|
||||||
|
{
|
||||||
|
rb_io_write(rb_deferr, mesg);
|
||||||
|
rb_io_write(rb_deferr, rb_default_rs);
|
||||||
|
return mesg;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
#ifdef HAVE_STDARG_PROTOTYPES
|
#ifdef HAVE_STDARG_PROTOTYPES
|
||||||
rb_bug(const char *fmt, ...)
|
rb_bug(const char *fmt, ...)
|
||||||
|
@ -653,6 +669,8 @@ Init_Exception()
|
||||||
rb_eNoMemError = rb_define_class("NoMemoryError", rb_eException);
|
rb_eNoMemError = rb_define_class("NoMemoryError", rb_eException);
|
||||||
|
|
||||||
init_syserr();
|
init_syserr();
|
||||||
|
|
||||||
|
rb_define_global_function("warn", rb_warn_m, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
18
eval.c
18
eval.c
|
@ -5041,6 +5041,7 @@ rb_call(klass, recv, mid, argc, argv, scope)
|
||||||
int noex;
|
int noex;
|
||||||
ID id = mid;
|
ID id = mid;
|
||||||
struct cache_entry *ent;
|
struct cache_entry *ent;
|
||||||
|
VALUE k = klass;
|
||||||
|
|
||||||
if (!klass) {
|
if (!klass) {
|
||||||
rb_raise(rb_eNotImpError, "method `%s' called on terminated object (0x%lx)",
|
rb_raise(rb_eNotImpError, "method `%s' called on terminated object (0x%lx)",
|
||||||
|
@ -5051,17 +5052,30 @@ rb_call(klass, recv, mid, argc, argv, scope)
|
||||||
if (ent->mid == mid && ent->klass == klass) {
|
if (ent->mid == mid && ent->klass == klass) {
|
||||||
if (!ent->method)
|
if (!ent->method)
|
||||||
return rb_undefined(recv, mid, argc, argv, scope==2?CSTAT_VCALL:0);
|
return rb_undefined(recv, mid, argc, argv, scope==2?CSTAT_VCALL:0);
|
||||||
klass = ent->origin;
|
k = ent->origin;
|
||||||
id = ent->mid0;
|
id = ent->mid0;
|
||||||
noex = ent->noex;
|
noex = ent->noex;
|
||||||
body = ent->method;
|
body = ent->method;
|
||||||
}
|
}
|
||||||
else if ((body = rb_get_method_body(&klass, &id, &noex)) == 0) {
|
else if ((body = rb_get_method_body(&k, &id, &noex)) == 0) {
|
||||||
if (scope == 3) {
|
if (scope == 3) {
|
||||||
return rb_undefined(recv, mid, argc, argv, CSTAT_SUPER);
|
return rb_undefined(recv, mid, argc, argv, CSTAT_SUPER);
|
||||||
}
|
}
|
||||||
return rb_undefined(recv, mid, argc, argv, scope==2?CSTAT_VCALL:0);
|
return rb_undefined(recv, mid, argc, argv, scope==2?CSTAT_VCALL:0);
|
||||||
}
|
}
|
||||||
|
if (BUILTIN_TYPE(k) == T_MODULE) {
|
||||||
|
while (!(BUILTIN_TYPE(klass) == T_ICLASS && RBASIC(klass)->klass == k)) {
|
||||||
|
klass = RCLASS(klass)->super;
|
||||||
|
if (!klass) {
|
||||||
|
rb_raise(rb_eTypeError, "%s is not included in %s",
|
||||||
|
rb_class2name(k),
|
||||||
|
rb_class2name(CLASS_OF(recv)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
klass = k;
|
||||||
|
}
|
||||||
|
|
||||||
if (mid != missing) {
|
if (mid != missing) {
|
||||||
/* receiver specified form for private method */
|
/* receiver specified form for private method */
|
||||||
|
|
11
io.c
11
io.c
|
@ -2738,15 +2738,6 @@ rb_write_deferr(mesg)
|
||||||
rb_write_deferr2(mesg, strlen(mesg));
|
rb_write_deferr2(mesg, strlen(mesg));
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
|
||||||
rb_warn_m(self, mesg)
|
|
||||||
VALUE self, mesg;
|
|
||||||
{
|
|
||||||
rb_io_write(rb_deferr, mesg);
|
|
||||||
rb_io_write(rb_deferr, rb_default_rs);
|
|
||||||
return mesg;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
must_respond_to(mid, val, id)
|
must_respond_to(mid, val, id)
|
||||||
ID mid;
|
ID mid;
|
||||||
|
@ -4091,6 +4082,4 @@ Init_IO()
|
||||||
#ifdef O_SYNC
|
#ifdef O_SYNC
|
||||||
rb_file_const("SYNC", INT2FIX(O_SYNC));
|
rb_file_const("SYNC", INT2FIX(O_SYNC));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
rb_define_global_function("warn", rb_warn_m, 1);
|
|
||||||
}
|
}
|
||||||
|
|
30
lib/cgi.rb
30
lib/cgi.rb
|
@ -494,7 +494,7 @@ status:
|
||||||
if defined?(MOD_RUBY)
|
if defined?(MOD_RUBY)
|
||||||
table = Apache::request.headers_out
|
table = Apache::request.headers_out
|
||||||
buf.scan(/([^:]+): (.+)#{EOL}/n){ |name, value|
|
buf.scan(/([^:]+): (.+)#{EOL}/n){ |name, value|
|
||||||
$stderr.printf("name:%s value:%s\n", name, value) if $DEBUG
|
warn sprintf("name:%s value:%s\n", name, value) if $DEBUG
|
||||||
case name
|
case name
|
||||||
when 'Set-Cookie'
|
when 'Set-Cookie'
|
||||||
table.add(name, value)
|
table.add(name, value)
|
||||||
|
@ -942,24 +942,30 @@ convert string charset, and set language to "ja".
|
||||||
private :initialize_query
|
private :initialize_query
|
||||||
|
|
||||||
class Value < String
|
class Value < String
|
||||||
def [](key)
|
def initialize(str, params)
|
||||||
$stderr.puts <<END
|
@params = params
|
||||||
CAUTION! cgi['key'] == cgi.params['key'][0] If want Array, use cgi.params['key']
|
super(str)
|
||||||
END
|
end
|
||||||
self
|
def [](idx)
|
||||||
|
p caller(1)
|
||||||
|
warn "#{caller(1)[0]}:CAUTION! cgi['key'] == cgi.params['key'][0]; if want Array, use cgi.params['key']"
|
||||||
|
self
|
||||||
end
|
end
|
||||||
def first
|
def first
|
||||||
$stderr.puts <<END
|
warn "#{caller(1)[0]}:CAUTION! cgi['key'] == cgi.params['key'][0]; if want Array, use cgi.params['key']"
|
||||||
CAUTION! cgi['key'] == cgi.params['key'][0] If want Array, use cgi.params['key']
|
self
|
||||||
END
|
end
|
||||||
self
|
alias last first
|
||||||
|
def to_a
|
||||||
|
@params
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def [](key)
|
def [](key)
|
||||||
value = @params[key][0]
|
params = @params[key]
|
||||||
|
value = params[0]
|
||||||
value ||= ""
|
value ||= ""
|
||||||
Value.new(value)
|
Value.new(value,params)
|
||||||
end
|
end
|
||||||
|
|
||||||
def keys(*args)
|
def keys(*args)
|
||||||
|
|
|
@ -39,7 +39,7 @@ class << File
|
||||||
end
|
end
|
||||||
|
|
||||||
def copy from, to, verbose = false
|
def copy from, to, verbose = false
|
||||||
$stderr.print from, " -> ", catname(from, to), "\n" if verbose
|
$deferr.print from, " -> ", catname(from, to), "\n" if verbose
|
||||||
syscopy from, to
|
syscopy from, to
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ class << File
|
||||||
|
|
||||||
def move from, to, verbose = false
|
def move from, to, verbose = false
|
||||||
to = catname(from, to)
|
to = catname(from, to)
|
||||||
$stderr.print from, " -> ", to, "\n" if verbose
|
$deferr.print from, " -> ", to, "\n" if verbose
|
||||||
|
|
||||||
if RUBY_PLATFORM =~ /djgpp|(cyg|ms|bcc)win|mingw/ and FileTest.file? to
|
if RUBY_PLATFORM =~ /djgpp|(cyg|ms|bcc)win|mingw/ and FileTest.file? to
|
||||||
unlink to
|
unlink to
|
||||||
|
@ -79,7 +79,7 @@ class << File
|
||||||
# false: not identical
|
# false: not identical
|
||||||
|
|
||||||
def compare from, to, verbose = false
|
def compare from, to, verbose = false
|
||||||
$stderr.print from, " <=> ", to, "\n" if verbose
|
$deferr.print from, " <=> ", to, "\n" if verbose
|
||||||
|
|
||||||
return false if stat(from).size != stat(to).size
|
return false if stat(from).size != stat(to).size
|
||||||
|
|
||||||
|
@ -116,11 +116,11 @@ class << File
|
||||||
def safe_unlink(*files)
|
def safe_unlink(*files)
|
||||||
verbose = if files[-1].is_a? String then false else files.pop end
|
verbose = if files[-1].is_a? String then false else files.pop end
|
||||||
begin
|
begin
|
||||||
$stderr.print files.join(" "), "\n" if verbose
|
$deferr.print files.join(" "), "\n" if verbose
|
||||||
chmod 0777, *files
|
chmod 0777, *files
|
||||||
unlink(*files)
|
unlink(*files)
|
||||||
rescue
|
rescue
|
||||||
# STDERR.print "warning: Couldn't unlink #{files.join ' '}\n"
|
# $deferr.print "warning: Couldn't unlink #{files.join ' '}\n"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -134,7 +134,7 @@ class << File
|
||||||
next if FileTest.directory? dir
|
next if FileTest.directory? dir
|
||||||
parent = dirname(dir)
|
parent = dirname(dir)
|
||||||
makedirs parent unless FileTest.directory? parent
|
makedirs parent unless FileTest.directory? parent
|
||||||
$stderr.print "mkdir ", dir, "\n" if verbose
|
$deferr.print "mkdir ", dir, "\n" if verbose
|
||||||
if basename(dir) != ""
|
if basename(dir) != ""
|
||||||
Dir.mkdir dir, mode
|
Dir.mkdir dir, mode
|
||||||
end
|
end
|
||||||
|
@ -148,7 +148,7 @@ class << File
|
||||||
vsave, $VERBOSE = $VERBOSE, false
|
vsave, $VERBOSE = $VERBOSE, false
|
||||||
def chmod(mode, *files)
|
def chmod(mode, *files)
|
||||||
verbose = if files[-1].is_a? String then false else files.pop end
|
verbose = if files[-1].is_a? String then false else files.pop end
|
||||||
$stderr.printf "chmod %04o %s\n", mode, files.join(" ") if verbose
|
$deferr.printf "chmod %04o %s\n", mode, files.join(" ") if verbose
|
||||||
o_chmod mode, *files
|
o_chmod mode, *files
|
||||||
end
|
end
|
||||||
$VERBOSE = vsave
|
$VERBOSE = vsave
|
||||||
|
|
|
@ -67,7 +67,7 @@ class GetoptLong
|
||||||
@argument_flags = Hash.new
|
@argument_flags = Hash.new
|
||||||
|
|
||||||
#
|
#
|
||||||
# Whether error messages are output to stderr.
|
# Whether error messages are output to $deferr.
|
||||||
#
|
#
|
||||||
@quiet = FALSE
|
@quiet = FALSE
|
||||||
|
|
||||||
|
@ -253,7 +253,7 @@ class GetoptLong
|
||||||
# Set an error (protected).
|
# Set an error (protected).
|
||||||
#
|
#
|
||||||
def set_error(type, message)
|
def set_error(type, message)
|
||||||
$stderr.print("#{$0}: #{message}\n") if !@quiet
|
$deferr.print("#{$0}: #{message}\n") if !@quiet
|
||||||
|
|
||||||
@error = type
|
@error = type
|
||||||
@error_message = message
|
@error_message = message
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
# jcode.rb - ruby code to handle japanese (EUC/SJIS) string
|
# jcode.rb - ruby code to handle japanese (EUC/SJIS) string
|
||||||
|
|
||||||
if $VERBOSE && $KCODE == "NONE"
|
if $VERBOSE && $KCODE == "NONE"
|
||||||
STDERR.puts "Warning: $KCODE is NONE."
|
warn "Warning: $KCODE is NONE."
|
||||||
end
|
end
|
||||||
|
|
||||||
$vsave, $VERBOSE = $VERBOSE, false
|
$vsave, $VERBOSE = $VERBOSE, false
|
||||||
class String
|
class String
|
||||||
printf STDERR, "feel free for some warnings:\n" if $VERBOSE
|
warn "feel free for some warnings:\n" if $VERBOSE
|
||||||
|
|
||||||
def _regex_quote(str)
|
def _regex_quote(str)
|
||||||
str.gsub(/(\\[\[\]\-\\])|\\(.)|([\[\]\\])/) do
|
str.gsub(/(\\[\[\]\-\\])|\\(.)|([\[\]\\])/) do
|
||||||
|
|
|
@ -78,7 +78,7 @@ if not $extmk and File.exist? Config::CONFIG["archdir"] + "/ruby.h"
|
||||||
elsif File.exist? $srcdir + "/ruby.h"
|
elsif File.exist? $srcdir + "/ruby.h"
|
||||||
$hdrdir = $srcdir
|
$hdrdir = $srcdir
|
||||||
else
|
else
|
||||||
STDERR.print "can't find header files for ruby.\n"
|
warn "can't find header files for ruby."
|
||||||
exit 1
|
exit 1
|
||||||
end
|
end
|
||||||
$topdir = $hdrdir
|
$topdir = $hdrdir
|
||||||
|
|
|
@ -1597,7 +1597,7 @@ Extends command line arguments array to parse itself.
|
||||||
begin
|
begin
|
||||||
yield @optparse
|
yield @optparse
|
||||||
rescue ParseError
|
rescue ParseError
|
||||||
STDERR.puts @optparse.program_name + ': ' + $!
|
warn @optparse.program_name + ': ' + $!
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
9
range.c
9
range.c
|
@ -369,27 +369,22 @@ rb_range_beg_len(range, begp, lenp, len, err)
|
||||||
}
|
}
|
||||||
if (err == 0 || err == 2) {
|
if (err == 0 || err == 2) {
|
||||||
if (beg > len) goto out_of_range;
|
if (beg > len) goto out_of_range;
|
||||||
if (end > len || (!EXCL(range) && end == len))
|
if (end > len)
|
||||||
end = len;
|
end = len;
|
||||||
}
|
}
|
||||||
if (end < 0) {
|
if (end < 0) {
|
||||||
end += len;
|
end += len;
|
||||||
if (end < 0) {
|
if (end < 0) {
|
||||||
if (beg == 0 && end == -1 && !EXCL(range)) {
|
|
||||||
len = 0;
|
|
||||||
goto length_set;
|
|
||||||
}
|
|
||||||
goto out_of_range;
|
goto out_of_range;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!EXCL(range)) end++; /* include end point */
|
||||||
len = end - beg;
|
len = end - beg;
|
||||||
if (!EXCL(range)) len++; /* include end point */
|
|
||||||
if (len < 0) goto out_of_range;
|
if (len < 0) goto out_of_range;
|
||||||
|
|
||||||
length_set:
|
length_set:
|
||||||
*begp = beg;
|
*begp = beg;
|
||||||
*lenp = len;
|
*lenp = len;
|
||||||
|
|
||||||
return Qtrue;
|
return Qtrue;
|
||||||
|
|
||||||
out_of_range:
|
out_of_range:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue