Skip to content

Commit 9d22a06

Browse files
author
matz
committed
* 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
1 parent a11ab83 commit 9d22a06

File tree

13 files changed

+157
-96
lines changed

13 files changed

+157
-96
lines changed

ChangeLog

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,43 @@
1+
Thu Jul 3 14:22:46 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
2+
3+
* array.c (rb_values_at): extract common procedure from
4+
rb_ary_values_at. follow DRY principle.
5+
6+
* re.c (match_values_at): values_at should understand ranges.
7+
8+
* struct.c (rb_struct_values_at): ditto.
9+
10+
* struct.c (inspect_struct): inspect format changed; add "struct "
11+
at the top.
12+
13+
* sprintf.c (rb_f_sprintf): "%p" specifier for inspect output.
14+
(RCR#68)
15+
16+
* eval.c (rb_mod_undef_method): allow "undef_method" to accept
17+
multiple arguments. (RCR#146)
18+
19+
* lib/timeout.rb: put timeout in Timeout module. (RCR#121)
20+
[ruby-talk:61028]
21+
22+
* re.c (match_groups): new method added. (RCR#139)
23+
24+
* variable.c (rb_mod_const_of): should exclude constant defined
25+
in Object, unless retrieving constants of Object.
26+
127
Thu Jul 3 12:13:05 2003 WATANABE Hirofumi <eban@ruby-lang.org>
228

329
* lib/mkmf.rb (VPATH): convert from Windows form to Unix form on
430
MinGW. This fixes the build with GNU make 3.80-1 for Cygwin.
531

32+
Wed Jul 2 23:27:34 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
33+
34+
* string.c (rb_str_new4): do not allocate new string if original
35+
is frozen or already have copy-on-write entry. [ruby-talk:74940]
36+
637
Wed Jul 2 13:22:39 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
738

39+
* string.c (rb_str_new4):
40+
841
* string.c (rb_str_shared_replace): clear flags before copy.
942

1043
* string.c (rb_str_replace): ditto.

array.c

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,29 +1218,37 @@ rb_ary_collect_bang(ary)
12181218
return ary;
12191219
}
12201220

1221-
static void
1222-
push_values_at(result, ary, arg)
1223-
VALUE result, ary, arg;
1221+
VALUE
1222+
rb_values_at(obj, olen, argc, argv, func)
1223+
VALUE obj;
1224+
long olen;
1225+
int argc;
1226+
VALUE *argv;
1227+
VALUE (*func) _((VALUE,long));
12241228
{
1225-
long beg, len, i;
1229+
VALUE result = rb_ary_new2(argc);
1230+
long beg, len, i, j;
12261231

1227-
if (FIXNUM_P(arg)) {
1228-
rb_ary_push(result, rb_ary_entry(ary, FIX2LONG(arg)));
1229-
return;
1230-
}
1231-
/* check if idx is Range */
1232-
switch (rb_range_beg_len(arg, &beg, &len, RARRAY(ary)->len, 0)) {
1233-
case Qfalse:
1234-
break;
1235-
case Qnil:
1236-
return;
1237-
default:
1238-
for (i=0; i<len; i++) {
1239-
rb_ary_push(result, rb_ary_entry(ary, i+beg));
1232+
for (i=0; i<argc; i++) {
1233+
if (FIXNUM_P(argv[i])) {
1234+
rb_ary_push(result, (*func)(obj, FIX2LONG(argv[i])));
1235+
continue;
1236+
}
1237+
/* check if idx is Range */
1238+
switch (rb_range_beg_len(argv[i], &beg, &len, olen, 0)) {
1239+
case Qfalse:
1240+
break;
1241+
case Qnil:
1242+
continue;
1243+
default:
1244+
for (j=0; j<len; j++) {
1245+
rb_ary_push(result, (*func)(obj, j+beg));
1246+
}
1247+
continue;
12401248
}
1241-
return;
1249+
rb_ary_push(result, (*func)(obj, NUM2LONG(argv[i])));
12421250
}
1243-
rb_ary_push(result, rb_ary_entry(ary, NUM2LONG(arg)));
1251+
return result;
12441252
}
12451253

12461254
static VALUE
@@ -1249,13 +1257,7 @@ rb_ary_values_at(argc, argv, ary)
12491257
VALUE *argv;
12501258
VALUE ary;
12511259
{
1252-
VALUE result = rb_ary_new2(argc);
1253-
long i;
1254-
1255-
for (i=0; i<argc; i++) {
1256-
push_values_at(result, ary, argv[i]);
1257-
}
1258-
return result;
1260+
return rb_values_at(ary, RARRAY(ary)->len, argc, argv, rb_ary_entry);
12591261
}
12601262

12611263
static VALUE

eval.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,7 @@ rb_get_method_body(klassp, idp, noexp)
362362
body = ent->method = body->nd_head;
363363
}
364364
else {
365+
if (BUILTIN_TYPE(origin) == T_ICLASS) origin = RBASIC(origin)->klass;
365366
*klassp = origin;
366367
ent->origin = origin;
367368
ent->mid = ent->mid0 = id;
@@ -1824,10 +1825,16 @@ rb_undef(klass, id)
18241825
}
18251826

18261827
static VALUE
1827-
rb_mod_undef_method(mod, name)
1828-
VALUE mod, name;
1828+
rb_mod_undef_method(argc, argv, mod)
1829+
int argc;
1830+
VALUE *argv;
1831+
VALUE mod;
18291832
{
1830-
rb_undef(mod, rb_to_id(name));
1833+
int i;
1834+
1835+
for (i=0; i<argc; i++) {
1836+
rb_undef(mod, rb_to_id(argv[i]));
1837+
}
18311838
return mod;
18321839
}
18331840

@@ -6521,7 +6528,7 @@ Init_eval()
65216528
rb_undef_method(rb_cClass, "module_function");
65226529

65236530
rb_define_private_method(rb_cModule, "remove_method", rb_mod_remove_method, 1);
6524-
rb_define_private_method(rb_cModule, "undef_method", rb_mod_undef_method, 1);
6531+
rb_define_private_method(rb_cModule, "undef_method", rb_mod_undef_method, -1);
65256532
rb_define_private_method(rb_cModule, "alias_method", rb_mod_alias_method, 2);
65266533
rb_define_private_method(rb_cModule, "define_method", rb_mod_define_method, -1);
65276534

intern.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ VALUE rb_ary_cmp _((VALUE, VALUE));
5656
VALUE rb_protect_inspect _((VALUE(*)(ANYARGS),VALUE,VALUE));
5757
VALUE rb_inspecting_p _((VALUE));
5858
VALUE rb_check_array_value _((VALUE));
59+
VALUE rb_values_at _((VALUE, long, int, VALUE*, VALUE(*) _((VALUE,long))));
5960
/* bignum.c */
6061
VALUE rb_big_clone _((VALUE));
6162
void rb_big_2comp _((VALUE));

lib/debug.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,9 +700,11 @@ def trace_func(event, file, line, id, binding, klass)
700700
@line = line
701701
case event
702702
when 'line'
703+
p [line, @stop_next]
703704
frame_set_pos(file, line)
704705
if !@no_step or @frames.size == @no_step
705706
@stop_next -= 1
707+
@stop_next = 0 if @stop_next < 0
706708
elsif @frames.size < @no_step
707709
@stop_next = 0 # break here before leaving...
708710
else

lib/irb/context.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ def inspect_mode=(opt)
177177
@inspect_mode
178178
end
179179

180+
undef use_readline=
180181
def use_readline=(opt)
181182
@use_readline = opt
182183
print "use readline module\n" if @use_readline

lib/mkmf.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
ORIG_LIBPATH = ENV['LIB']
99

1010
SRC_EXT = ["c", "cc", "m", "cxx", "cpp", "C"]
11+
$static = $config_h = nil
1112

1213
unless defined? $configure_args
1314
$configure_args = {}

lib/timeout.rb

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,38 @@
2323
#
2424
# The time in seconds to wait for block teminatation.
2525
#
26+
# : [exception]
27+
#
28+
# The exception classs to be raised on timeout.
29+
#
2630
#=end
2731

28-
class TimeoutError<Interrupt
29-
end
32+
module Timeout
33+
class Error<Interrupt
34+
end
3035

31-
def timeout(sec, exception=TimeoutError)
32-
return yield if sec == nil
33-
begin
34-
x = Thread.current
35-
y = Thread.start {
36-
sleep sec
37-
x.raise exception, "execution expired" if x.alive?
38-
}
39-
yield sec
40-
# return true
41-
ensure
42-
y.kill if y and y.alive?
36+
def timeout(sec, exception=Error)
37+
return yield if sec == nil
38+
begin
39+
x = Thread.current
40+
y = Thread.start {
41+
sleep sec
42+
x.raise exception, "execution expired" if x.alive?
43+
}
44+
yield sec
45+
# return true
46+
ensure
47+
y.kill if y and y.alive?
48+
end
4349
end
50+
module_function :timeout
51+
end
52+
53+
# compatible
54+
def timeout(n, &block)
55+
Timeout::timeout(n, &block)
4456
end
57+
TimeoutError = Timeout::Error
4558

4659
if __FILE__ == $0
4760
p timeout(5) {

re.c

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -914,16 +914,17 @@ last_paren_match_getter()
914914
}
915915

916916
static VALUE
917-
match_to_a(match)
917+
match_array(match, start)
918918
VALUE match;
919+
int start;
919920
{
920921
struct re_registers *regs = RMATCH(match)->regs;
921922
VALUE ary = rb_ary_new2(regs->num_regs);
922923
VALUE target = RMATCH(match)->str;
923924
int i;
924925
int taint = OBJ_TAINTED(match);
925926

926-
for (i=0; i<regs->num_regs; i++) {
927+
for (i=start; i<regs->num_regs; i++) {
927928
if (regs->beg[i] == -1) {
928929
rb_ary_push(ary, Qnil);
929930
}
@@ -936,6 +937,20 @@ match_to_a(match)
936937
return ary;
937938
}
938939

940+
static VALUE
941+
match_to_a(match)
942+
VALUE match;
943+
{
944+
return match_array(match, 0);
945+
}
946+
947+
static VALUE
948+
match_groups(match)
949+
VALUE match;
950+
{
951+
return match_array(match, 1);
952+
}
953+
939954
static VALUE
940955
match_aref(argc, argv, match)
941956
int argc;
@@ -952,32 +967,21 @@ match_aref(argc, argv, match)
952967
return rb_reg_nth_match(FIX2INT(idx), match);
953968
}
954969

970+
static VALUE
971+
match_entry(match, n)
972+
VALUE match;
973+
long n;
974+
{
975+
return rb_reg_nth_match(n, match);
976+
}
977+
955978
static VALUE
956979
match_values_at(argc, argv, match)
957980
int argc;
958981
VALUE *argv;
959982
VALUE match;
960983
{
961-
struct re_registers *regs = RMATCH(match)->regs;
962-
VALUE target = RMATCH(match)->str;
963-
VALUE result = rb_ary_new();
964-
int i;
965-
long idx;
966-
int taint = OBJ_TAINTED(match);
967-
968-
for (i=0; i<argc; i++) {
969-
idx = NUM2LONG(argv[i]);
970-
if (idx < 0) idx += regs->num_regs;
971-
if (idx < 0 || regs->num_regs <= idx) {
972-
rb_ary_push(result, Qnil);
973-
}
974-
else {
975-
VALUE str = rb_str_substr(target, regs->beg[idx], regs->end[idx]-regs->beg[idx]);
976-
if (taint) OBJ_TAINT(str);
977-
rb_ary_push(result, str);
978-
}
979-
}
980-
return result;
984+
return rb_values_at(match, RMATCH(match)->regs->num_regs, argc, argv, match_entry);
981985
}
982986

983987
static VALUE
@@ -1766,6 +1770,7 @@ Init_Regexp()
17661770
rb_define_method(rb_cMatch, "end", match_end, 1);
17671771
rb_define_method(rb_cMatch, "to_a", match_to_a, 0);
17681772
rb_define_method(rb_cMatch, "[]", match_aref, -1);
1773+
rb_define_method(rb_cMatch, "groups", match_groups, 0);
17691774
rb_define_method(rb_cMatch, "select", match_select, -1);
17701775
rb_define_method(rb_cMatch, "values_at", match_values_at, -1);
17711776
rb_define_method(rb_cMatch, "pre_match", rb_reg_match_pre, 0);

sprintf.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,10 +291,12 @@ rb_f_sprintf(argc, argv)
291291
break;
292292

293293
case 's':
294+
case 'p':
294295
{
295296
VALUE arg = GETARG();
296297
long len;
297298

299+
if (*p == 'p') arg = rb_inspect(arg);
298300
str = rb_obj_as_string(arg);
299301
if (OBJ_TAINTED(str)) tainted = 1;
300302
len = RSTRING(str)->len;

0 commit comments

Comments
 (0)