Skip to content

Commit c8bd43a

Browse files
author
matz
committed
arity/strict yield
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_3@469 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent 32599f5 commit c8bd43a

File tree

19 files changed

+380
-179
lines changed

19 files changed

+380
-179
lines changed

ChangeLog

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,37 @@
1+
Mon May 17 12:26:31 1999 Yukihiro Matsumoto <matz@netlab.co.jp>
2+
3+
* parse.y (read_escape): char may be unsigned.
4+
5+
* string.c (rb_str_succ): ditto.
6+
7+
* string.c (tr_trans): ditto.
8+
9+
* object.c (Init_Object): methods `&', `|', `^' are added to nil.
10+
11+
* range.c (rb_range_beg_len): it should be OK for [0..-len-1].
12+
13+
* regex.c (re_search): search for byte literal within mbcs.
14+
15+
* regex.c (is_in_list): parsh
16+
17+
* regex.c (re_compile_fastmap): should have not alter the loop
18+
variable `j' if TRASLATE_P().
19+
20+
* regex.c (re_compile_pattern): escaped characters should be read
21+
by PATFETCH_RAW(c).
22+
23+
Sat May 15 11:23:51 1999 Yukihiro Matsumoto <matz@netlab.co.jp>
24+
25+
* regex.c (re_match): endline2 (\Z) should not match at the point
26+
between a newline and end-of-line, like endline ($).
27+
28+
* class.c (include_class_new): should initialize iv_tbl to share
29+
between module and iclass.
30+
31+
Fri May 14 08:50:27 1999 Akira Endo <akendo@t3.rim.or.jp>
32+
33+
* regex.c (re_compile_fastmap): it should be k != 0 to skip.
34+
135
Fri May 14 12:46:56 1999 Yukihiro Matsumoto <matz@netlab.co.jp>
236

337
* time.c (time_load): a bug in old marshal format support.

class.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,11 @@ include_class_new(module, super)
199199
NEWOBJ(klass, struct RClass);
200200
OBJSETUP(klass, rb_cClass, T_ICLASS);
201201

202-
klass->m_tbl = RCLASS(module)->m_tbl;
202+
if (!RCLASS(module)->iv_tbl) {
203+
RCLASS(module)->iv_tbl = st_init_numtable();
204+
}
203205
klass->iv_tbl = RCLASS(module)->iv_tbl;
206+
klass->m_tbl = RCLASS(module)->m_tbl;
204207
klass->super = super;
205208
if (TYPE(module) == T_ICLASS) {
206209
RBASIC(klass)->klass = RBASIC(module)->klass;

dln.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1348,7 +1348,7 @@ dln_load(file)
13481348
if (init_fct == NULL) {
13491349
aix_loaderror(file);
13501350
}
1351-
if (loadbind(0, main_module, init_fct) == -1) {
1351+
if (loadbind(0, main_module, (void*)init_fct) == -1) {
13521352
aix_loaderror(file);
13531353
}
13541354
(*init_fct)();

eval.c

Lines changed: 106 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -681,8 +681,8 @@ static VALUE rb_yield_0 _((VALUE, VALUE, VALUE));
681681
static VALUE rb_call _((VALUE,VALUE,ID,int,VALUE*,int));
682682
static VALUE module_setup _((VALUE,NODE*));
683683

684-
static VALUE massign _((VALUE,NODE*,VALUE));
685-
static void assign _((VALUE,NODE*,VALUE));
684+
static VALUE massign _((VALUE,NODE*,VALUE,int));
685+
static void assign _((VALUE,NODE*,VALUE,int));
686686

687687
static int safe_level = 0;
688688
/* safe-level:
@@ -2314,7 +2314,7 @@ rb_eval(self, node)
23142314
break;
23152315

23162316
case NODE_MASGN:
2317-
result = massign(self, node, rb_eval(self, node->nd_value));
2317+
result = massign(self, node, rb_eval(self, node->nd_value),0);
23182318
break;
23192319

23202320
case NODE_LASGN:
@@ -3162,10 +3162,15 @@ rb_yield_0(val, self, klass)
31623162
if (!self) self = block->self;
31633163
node = block->body;
31643164
if (block->var) {
3165-
if (nd_type(block->var) == NODE_MASGN)
3166-
massign(self, block->var, val);
3167-
else
3168-
assign(self, block->var, val);
3165+
PUSH_TAG(PROT_NONE);
3166+
if ((state = EXEC_TAG()) == 0) {
3167+
if (nd_type(block->var) == NODE_MASGN)
3168+
massign(self, block->var, val, 1);
3169+
else
3170+
assign(self, block->var, val, 1);
3171+
}
3172+
POP_TAG();
3173+
if (state) goto pop_state;
31693174
}
31703175
PUSH_ITER(block->iter);
31713176
PUSH_TAG(PROT_NONE);
@@ -3201,6 +3206,7 @@ rb_yield_0(val, self, klass)
32013206
}
32023207
}
32033208
POP_TAG();
3209+
pop_state:
32043210
POP_ITER();
32053211
POP_CLASS();
32063212
POP_VARS();
@@ -3227,13 +3233,14 @@ rb_f_loop()
32273233
}
32283234

32293235
static VALUE
3230-
massign(self, node, val)
3236+
massign(self, node, val, check)
32313237
VALUE self;
32323238
NODE *node;
32333239
VALUE val;
3240+
int check;
32343241
{
32353242
NODE *list;
3236-
int i, len;
3243+
int i = 0, len;
32373244

32383245
list = node->nd_head;
32393246

@@ -3243,33 +3250,46 @@ massign(self, node, val)
32433250
}
32443251
len = RARRAY(val)->len;
32453252
for (i=0; list && i<len; i++) {
3246-
assign(self, list->nd_head, RARRAY(val)->ptr[i]);
3253+
assign(self, list->nd_head, RARRAY(val)->ptr[i], check);
32473254
list = list->nd_next;
32483255
}
3256+
if (check && list) goto arg_error;
32493257
if (node->nd_args) {
32503258
if (!list && i<len) {
3251-
assign(self, node->nd_args, rb_ary_new4(len-i, RARRAY(val)->ptr+i));
3259+
assign(self, node->nd_args, rb_ary_new4(len-i, RARRAY(val)->ptr+i), check);
32523260
}
32533261
else {
3254-
assign(self, node->nd_args, rb_ary_new2(0));
3262+
assign(self, node->nd_args, rb_ary_new2(0), check);
32553263
}
32563264
}
3265+
else if (check && i<len) goto arg_error;
32573266
}
32583267
else if (node->nd_args) {
3259-
assign(self, node->nd_args, Qnil);
3268+
assign(self, node->nd_args, Qnil, check);
32603269
}
3270+
3271+
if (check && list) goto arg_error;
32613272
while (list) {
3262-
assign(self, list->nd_head, Qnil);
3273+
i++;
3274+
assign(self, list->nd_head, Qnil, check);
32633275
list = list->nd_next;
32643276
}
32653277
return val;
3278+
3279+
arg_error:
3280+
while (list) {
3281+
i++;
3282+
list = list->nd_next;
3283+
}
3284+
rb_raise(rb_eArgError, "wrong # of arguments (%d for %d)", len, i);
32663285
}
32673286

32683287
static void
3269-
assign(self, lhs, val)
3288+
assign(self, lhs, val, check)
32703289
VALUE self;
32713290
NODE *lhs;
32723291
VALUE val;
3292+
int check;
32733293
{
32743294
switch (nd_type(lhs)) {
32753295
case NODE_GASGN:
@@ -3299,7 +3319,7 @@ assign(self, lhs, val)
32993319
break;
33003320

33013321
case NODE_MASGN:
3302-
massign(self, lhs, val);
3322+
massign(self, lhs, val, check);
33033323
break;
33043324

33053325
case NODE_CALL:
@@ -3852,7 +3872,7 @@ rb_call0(klass, recv, id, argc, argv, body, nosuper)
38523872
NODE *opt = node->nd_opt;
38533873

38543874
while (opt && argc) {
3855-
assign(recv, opt->nd_head, *argv);
3875+
assign(recv, opt->nd_head, *argv, 1);
38563876
argv++; argc--;
38573877
opt = opt->nd_next;
38583878
}
@@ -5427,10 +5447,19 @@ proc_call(proc, args)
54275447
struct BLOCK * volatile old_block;
54285448
struct BLOCK *data;
54295449
volatile VALUE result = Qnil;
5430-
int state;
5450+
int state, n;
54315451
volatile int orphan;
54325452
volatile int safe = safe_level;
54335453

5454+
Data_Get_Struct(proc, struct BLOCK, data);
5455+
orphan = blk_orphan(data);
5456+
5457+
/* PUSH BLOCK from data */
5458+
old_block = ruby_block;
5459+
ruby_block = data;
5460+
PUSH_ITER(ITER_CUR);
5461+
ruby_frame->iter = ITER_CUR;
5462+
54345463
if (TYPE(args) == T_ARRAY) {
54355464
switch (RARRAY(args)->len) {
54365465
case 0:
@@ -5442,15 +5471,6 @@ proc_call(proc, args)
54425471
}
54435472
}
54445473

5445-
Data_Get_Struct(proc, struct BLOCK, data);
5446-
orphan = blk_orphan(data);
5447-
5448-
/* PUSH BLOCK from data */
5449-
old_block = ruby_block;
5450-
ruby_block = data;
5451-
PUSH_ITER(ITER_CUR);
5452-
ruby_frame->iter = ITER_CUR;
5453-
54545474
if (orphan) {/* orphan procedure */
54555475
if (rb_iterator_p()) {
54565476
ruby_block->frame.iter = ITER_CUR;
@@ -5494,6 +5514,31 @@ proc_call(proc, args)
54945514
return result;
54955515
}
54965516

5517+
static VALUE
5518+
proc_arity(proc)
5519+
VALUE proc;
5520+
{
5521+
struct BLOCK *data;
5522+
NODE *list;
5523+
int n;
5524+
5525+
Data_Get_Struct(proc, struct BLOCK, data);
5526+
if (data->var == 0) return 0;
5527+
switch (nd_type(data->var)) {
5528+
default:
5529+
return INT2FIX(-1);
5530+
case NODE_MASGN:
5531+
list = data->var->nd_head;
5532+
n = 0;
5533+
while (list) {
5534+
n++;
5535+
list = list->nd_next;
5536+
}
5537+
if (data->var->nd_args) return INT2FIX(-n);
5538+
return INT2FIX(n);
5539+
}
5540+
}
5541+
54975542
static VALUE
54985543
block_pass(self, node)
54995544
VALUE self;
@@ -5645,6 +5690,38 @@ method_call(argc, argv, method)
56455690
return result;
56465691
}
56475692

5693+
static VALUE
5694+
method_arity(method)
5695+
VALUE method;
5696+
{
5697+
struct METHOD *data;
5698+
NODE *body;
5699+
int n;
5700+
5701+
Data_Get_Struct(method, struct METHOD, data);
5702+
5703+
body = data->body;
5704+
switch (nd_type(body)) {
5705+
case NODE_CFUNC:
5706+
if (body->nd_argc < 0) return INT2FIX(-1);
5707+
return INT2FIX(body->nd_argc);
5708+
case NODE_ZSUPER:
5709+
return INT2FIX(-1);
5710+
case NODE_ATTRSET:
5711+
return INT2FIX(1);
5712+
case NODE_IVAR:
5713+
return INT2FIX(0);
5714+
default:
5715+
body = body->nd_next; /* skip NODE_SCOPE */
5716+
if (nd_type(body) == NODE_BLOCK)
5717+
body = body->nd_head;
5718+
if (!body) return INT2FIX(0);
5719+
n = body->nd_cnt;
5720+
if (body->nd_rest) n = -n;
5721+
return INT2FIX(n);
5722+
}
5723+
}
5724+
56485725
static VALUE
56495726
method_inspect(method)
56505727
VALUE method;
@@ -5710,6 +5787,7 @@ Init_Proc()
57105787
rb_define_singleton_method(rb_cProc, "new", proc_s_new, 0);
57115788

57125789
rb_define_method(rb_cProc, "call", proc_call, -2);
5790+
rb_define_method(rb_cProc, "arity", proc_arity, 0);
57135791
rb_define_method(rb_cProc, "[]", proc_call, -2);
57145792
rb_define_global_function("proc", rb_f_lambda, 0);
57155793
rb_define_global_function("lambda", rb_f_lambda, 0);
@@ -5722,6 +5800,7 @@ Init_Proc()
57225800
rb_undef_method(CLASS_OF(rb_cMethod), "new");
57235801
rb_define_method(rb_cMethod, "call", method_call, -1);
57245802
rb_define_method(rb_cMethod, "[]", method_call, -1);
5803+
rb_define_method(rb_cMethod, "arity", method_arity, 0);
57255804
rb_define_method(rb_cMethod, "inspect", method_inspect, 0);
57265805
rb_define_method(rb_cMethod, "to_s", method_inspect, 0);
57275806
rb_define_method(rb_cMethod, "to_proc", method_proc, 0);

ext/extmk.rb.nt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ def older(file1, file2)
5959
return false
6060
end
6161

62+
CFLAGS = ""
6263
#LINK = "cl -o conftest.exe -I../.. -Zi -O -I. %s conftest.c %s > nul"
6364
LINK = "cl -o conftest.exe -Zi -O %s conftest.c %s > nul"
6465
CPP = "cl -E -I../.. -I../../missing -I../../win32 -I. -Zi -O %s conftest.c > nul"
@@ -435,8 +436,6 @@ def extmake(target)
435436

436437
return if $nodynamic and not $static
437438

438-
$CFLAGS = nil
439-
$LDFLAGS = nil
440439
$LOCAL_LIBS = "" # to be assigned in extconf.rb
441440
$CFLAGS = ""
442441
$LDFLAGS = ""

ext/gdbm/extconf.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require 'mkmf'
22
$LDFLAGS = "-L/usr/local/lib"
3-
have_library("gdbm", "gdbm_open")
4-
have_header("gdbm.h")
5-
if have_func("gdbm_open")
3+
if have_library("gdbm", "gdbm_open") and
4+
have_header("gdbm.h") and
5+
have_func("gdbm_open") then
66
create_makefile("gdbm")
77
end

ext/pty/pty.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ chld_changed()
180180
rb_raise(rb_eRuntimeError, "Stopped: %d",cpid);
181181
}
182182
#else
183-
#error "Either IF_STOPPED or WIFSTOPPED is needed"
183+
---->> Either IF_STOPPED or WIFSTOPPED is needed <<----
184184
#endif /* WIFSTOPPED */
185185
#endif /* IF_STOPPED */
186186
if (n >= 0) {

0 commit comments

Comments
 (0)