Skip to content

Commit dde62bc

Browse files
author
matz
committed
2000-01-17
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@606 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent e438777 commit dde62bc

File tree

21 files changed

+390
-255
lines changed

21 files changed

+390
-255
lines changed

ChangeLog

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,40 @@
1+
Sat Jan 15 22:21:08 2000 Nobuyoshi Nakada <nobu.nakada@nifty.ne.jp>
2+
3+
* eval.c (search_method): argument klass may be 0.
4+
5+
Sat Jan 15 15:03:46 2000 Yukihiro Matsumoto <matz@netlab.co.jp>
6+
7+
* enum.c (enum_index): remove this method.
8+
9+
* enum.c: remove use of pointers to local variables. find,
10+
find_all, min, max, index, member?, each_with_index,
11+
12+
* eval.c (massign): multiple assignment does not use to_a anymore.
13+
experimental.
14+
15+
Fri Jan 14 12:22:04 2000 Yukihiro Matsumoto <matz@netlab.co.jp>
16+
17+
* string.c (rb_str_replace): use memmove instead of memcpy for
18+
overwrapping strings (e.g. a[1] = a).
19+
20+
Thu Jan 13 11:12:40 2000 Yukihiro Matsumoto <matz@netlab.co.jp>
21+
22+
* parse.y (arg_add): use new node, ARGSPUSH.
23+
24+
Mon Jan 10 18:32:28 2000 Koji Arai <JCA02266@nifty.ne.jp>
25+
26+
* marshal.c (w_object): forgot an argument to call w_ivar().
27+
28+
Sun Jan 9 18:13:51 2000 Katsuyuki Komatsu <komatsu@sarion.co.jp>
29+
30+
* random.c: first was not defined unless HAVE_RANDOM.
31+
32+
Sat Jan 8 19:02:49 2000 Yukihiro Matsumoto <matz@netlab.co.jp>
33+
34+
* io.c (rb_io_sysread): raise IOError for buffered IO.
35+
36+
* ext/socket/socket.c (s_recv): ditto.
37+
138
Fri Jan 7 00:59:29 2000 Masahiro Tomita <tommy@tmtm.org>
239

340
* io.c (io_fread): TRAP_BEG/TRAP_END added around getc().
@@ -123,6 +160,10 @@ Tue Dec 21 17:21:28 1999 Koji Oda <oda@bsd1.qnes.nec.co.jp>
123160

124161
* ext/socket/socket.c (sock_finalize): mswin32: fix FILE* leak.
125162

163+
Mon Dec 20 19:08:12 1999 Nobuyoshi Nakada <nobu.nakada@nifty.ne.jp>
164+
165+
* file.c (rb_file_s_expand_path): handle dir separetor correctly.
166+
126167
Sun Dec 19 22:56:31 1999 KANEKO Naoshi <wbs01621@mail.wbs.ne.jp>
127168

128169
* lib/find.rb: support dosish root directory.

ToDo

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Hacking Interpreter
3434
* syntax tree -> bytecode ???
3535
* scrambled script, or script filter
3636
* setuid ruby
37+
* freeze all object
3738

3839
Standard Libraries
3940

enum.c

Lines changed: 65 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
************************************************/
1212

1313
#include "ruby.h"
14+
#include "node.h"
1415

1516
VALUE rb_mEnumerable;
1617
static ID id_each, id_eqq, id_cmp;
@@ -58,19 +59,14 @@ enum_grep(obj, pat)
5859
return tmp;
5960
}
6061

61-
struct find_arg {
62-
int found;
63-
VALUE val;
64-
};
65-
6662
static VALUE
67-
find_i(i, arg)
63+
find_i(i, memo)
6864
VALUE i;
69-
struct find_arg *arg;
65+
NODE *memo;
7066
{
7167
if (RTEST(rb_yield(i))) {
72-
arg->found = Qtrue;
73-
arg->val = i;
68+
memo->u2.value = Qtrue;
69+
memo->u1.value = i;
7470
rb_iter_break();
7571
}
7672
return Qnil;
@@ -82,18 +78,19 @@ enum_find(argc, argv, obj)
8278
VALUE* argv;
8379
VALUE obj;
8480
{
85-
struct find_arg arg;
81+
NODE *memo = rb_node_newnode(NODE_MEMO, Qnil, Qfalse, 0);
8682
VALUE if_none;
8783

8884
rb_scan_args(argc, argv, "01", &if_none);
89-
arg.found = Qfalse;
90-
rb_iterate(rb_each, obj, find_i, (VALUE)&arg);
91-
if (arg.found) {
92-
return arg.val;
85+
rb_iterate(rb_each, obj, find_i, (VALUE)memo);
86+
if (memo->u2.value) {
87+
rb_gc_force_recycle((VALUE)memo);
88+
return memo->u1.value;
9389
}
9490
if (!NIL_P(if_none)) {
9591
rb_eval_cmd(if_none, Qnil);
9692
}
93+
rb_gc_force_recycle((VALUE)memo);
9794
return Qnil;
9895
}
9996

@@ -189,33 +186,35 @@ enum_sort(obj)
189186
}
190187

191188
static VALUE
192-
min_i(i, min)
193-
VALUE i, *min;
189+
min_i(i, memo)
190+
VALUE i;
191+
NODE *memo;
194192
{
195193
VALUE cmp;
196194

197-
if (NIL_P(*min))
198-
*min = i;
195+
if (NIL_P(memo->u1.value))
196+
memo->u1.value = i;
199197
else {
200-
cmp = rb_funcall(i, id_cmp, 1, *min);
198+
cmp = rb_funcall(i, id_cmp, 1, memo->u1.value);
201199
if (NUM2LONG(cmp) < 0)
202-
*min = i;
200+
memo->u1.value = i;
203201
}
204202
return Qnil;
205203
}
206204

207205
static VALUE
208-
min_ii(i, min)
209-
VALUE i, *min;
206+
min_ii(i, memo)
207+
VALUE i;
208+
NODE *memo;
210209
{
211210
VALUE cmp;
212211

213-
if (NIL_P(*min))
214-
*min = i;
212+
if (NIL_P(memo->u1.value))
213+
memo->u1.value = i;
215214
else {
216-
cmp = rb_yield(rb_assoc_new(i, *min));
215+
cmp = rb_yield(rb_assoc_new(i, memo->u1.value));
217216
if (NUM2LONG(cmp) < 0)
218-
*min = i;
217+
memo->u1.value = i;
219218
}
220219
return Qnil;
221220
}
@@ -224,40 +223,43 @@ static VALUE
224223
enum_min(obj)
225224
VALUE obj;
226225
{
227-
VALUE min = Qnil;
226+
NODE *memo = rb_node_newnode(NODE_MEMO, Qnil, 0, 0);
228227

229-
rb_iterate(rb_each, obj, rb_iterator_p()?min_ii:min_i, (VALUE)&min);
230-
return min;
228+
rb_iterate(rb_each, obj, rb_iterator_p()?min_ii:min_i, (VALUE)memo);
229+
rb_gc_force_recycle((VALUE)memo);
230+
return memo->u1.value;
231231
}
232232

233233
static VALUE
234-
max_i(i, max)
235-
VALUE i, *max;
234+
max_i(i, memo)
235+
VALUE i;
236+
NODE *memo;
236237
{
237238
VALUE cmp;
238239

239-
if (NIL_P(*max))
240-
*max = i;
240+
if (NIL_P(memo->u1.value))
241+
memo->u1.value = i;
241242
else {
242-
cmp = rb_funcall(i, id_cmp, 1, *max);
243+
cmp = rb_funcall(i, id_cmp, 1, memo->u1.value);
243244
if (NUM2LONG(cmp) > 0)
244-
*max = i;
245+
memo->u1.value = i;
245246
}
246247
return Qnil;
247248
}
248249

249250
static VALUE
250-
max_ii(i, max)
251-
VALUE i, *max;
251+
max_ii(i, memo)
252+
VALUE i;
253+
NODE *memo;
252254
{
253255
VALUE cmp;
254256

255-
if (NIL_P(*max))
256-
*max = i;
257+
if (NIL_P(memo->u1.value))
258+
memo->u1.value = i;
257259
else {
258-
cmp = rb_yield(rb_assoc_new(i, *max));
260+
cmp = rb_yield(rb_assoc_new(i, memo->u1.value));
259261
if (NUM2LONG(cmp) > 0)
260-
*max = i;
262+
memo->u1.value = i;
261263
}
262264
return Qnil;
263265
}
@@ -266,54 +268,20 @@ static VALUE
266268
enum_max(obj)
267269
VALUE obj;
268270
{
269-
VALUE max = Qnil;
270-
271-
rb_iterate(rb_each, obj, rb_iterator_p()?max_ii:max_i, (VALUE)&max);
272-
return max;
273-
}
274-
275-
struct i_v_pair {
276-
int i;
277-
VALUE v;
278-
int found;
279-
};
280-
281-
static VALUE
282-
index_i(item, iv)
283-
VALUE item;
284-
struct i_v_pair *iv;
285-
{
286-
if (rb_equal(item, iv->v)) {
287-
iv->found = 1;
288-
rb_iter_break();
289-
}
290-
else {
291-
iv->i++;
292-
}
293-
return Qnil;
294-
}
271+
NODE *memo = rb_node_newnode(NODE_MEMO, Qnil, 0, 0);
295272

296-
static VALUE
297-
enum_index(obj, val)
298-
VALUE obj, val;
299-
{
300-
struct i_v_pair iv;
301-
302-
iv.i = 0;
303-
iv.v = val;
304-
iv.found = 0;
305-
rb_iterate(rb_each, obj, index_i, (VALUE)&iv);
306-
if (iv.found) return INT2FIX(iv.i);
307-
return Qnil; /* not found */
273+
rb_iterate(rb_each, obj, rb_iterator_p()?max_ii:max_i, (VALUE)memo);
274+
rb_gc_force_recycle((VALUE)memo);
275+
return memo->u1.value;
308276
}
309277

310278
static VALUE
311-
member_i(item, iv)
279+
member_i(item, memo)
312280
VALUE item;
313-
struct i_v_pair *iv;
281+
NODE *memo;
314282
{
315-
if (rb_equal(item, iv->v)) {
316-
iv->i = 1;
283+
if (rb_equal(item, memo->u1.value)) {
284+
memo->u2.value = Qtrue;
317285
rb_iter_break();
318286
}
319287
return Qnil;
@@ -323,36 +291,34 @@ static VALUE
323291
enum_member(obj, val)
324292
VALUE obj, val;
325293
{
326-
struct i_v_pair iv;
294+
VALUE result;
295+
296+
NODE *memo = rb_node_newnode(NODE_MEMO, val, Qfalse, 0);
327297

328-
iv.i = 0;
329-
iv.v = val;
330-
rb_iterate(rb_each, obj, member_i, (VALUE)&iv);
331-
if (iv.i) return Qtrue;
332-
return Qfalse;
298+
rb_iterate(rb_each, obj, member_i, (VALUE)memo);
299+
result = memo->u2.value;
300+
rb_gc_force_recycle((VALUE)memo);
301+
return result;
333302
}
334303

335304
static VALUE
336-
each_with_index_i(val, indexp)
305+
each_with_index_i(val, memo)
337306
VALUE val;
338-
int *indexp;
307+
NODE *memo;
339308
{
340-
#if 1
341-
rb_yield(rb_assoc_new(val, INT2FIX(*indexp)));
342-
#else
343-
rb_yield(rb_ary_concat(rb_Array(val), INT2FIX(*indexp)));
344-
#endif
345-
(*indexp)++;
309+
rb_yield(rb_assoc_new(val, INT2FIX(memo->u3.cnt)));
310+
memo->u3.cnt++;
346311
return Qnil;
347312
}
348313

349314
static VALUE
350315
enum_each_with_index(obj)
351316
VALUE obj;
352317
{
353-
int index = 0;
318+
NODE *memo = rb_node_newnode(NODE_MEMO, 0, 0, 0);
354319

355-
rb_iterate(rb_each, obj, each_with_index_i, (VALUE)&index);
320+
rb_iterate(rb_each, obj, each_with_index_i, (VALUE)memo);
321+
rb_gc_force_recycle((VALUE)memo);
356322
return Qnil;
357323
}
358324

@@ -374,7 +340,6 @@ Init_Enumerable()
374340
rb_define_method(rb_mEnumerable,"collect", enum_collect, 0);
375341
rb_define_method(rb_mEnumerable,"min", enum_min, 0);
376342
rb_define_method(rb_mEnumerable,"max", enum_max, 0);
377-
rb_define_method(rb_mEnumerable,"index", enum_index, 1);
378343
rb_define_method(rb_mEnumerable,"member?", enum_member, 1);
379344
rb_define_method(rb_mEnumerable,"include?", enum_member, 1);
380345
rb_define_method(rb_mEnumerable,"each_with_index", enum_each_with_index, 0);

eval.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ search_method(klass, id, origin)
239239
{
240240
NODE *body;
241241

242+
if (!klass) return 0;
242243
while (!st_lookup(RCLASS(klass)->m_tbl, id, &body)) {
243244
klass = RCLASS(klass)->super;
244245
if (!klass) return 0;
@@ -2284,6 +2285,11 @@ rb_eval(self, node)
22842285
rb_eval(self, node->nd_body));
22852286
break;
22862287

2288+
case NODE_ARGSPUSH:
2289+
result = rb_ary_push(rb_eval(self, node->nd_head),
2290+
rb_eval(self, node->nd_body));
2291+
break;
2292+
22872293
case NODE_CALL:
22882294
{
22892295
VALUE recv;
@@ -3333,10 +3339,13 @@ rb_yield_0(val, self, klass, acheck)
33333339
!FL_TEST(ruby_dyna_vars, DVAR_DONT_RECYCLE)) {
33343340
struct RVarmap *vars = ruby_dyna_vars;
33353341

3336-
do {
3342+
while (vars && vars->id != 0) {
33373343
rb_gc_force_recycle((VALUE)vars);
33383344
vars = vars->next;
3339-
} while (vars && vars->id != 0);
3345+
}
3346+
if (ruby_dyna_vars->id == 0) {
3347+
rb_gc_force_recycle((VALUE)ruby_dyna_vars);
3348+
}
33403349
}
33413350
POP_VARS();
33423351
ruby_block = block;
@@ -3379,7 +3388,10 @@ massign(self, node, val, check)
33793388

33803389
if (val) {
33813390
if (TYPE(val) != T_ARRAY) {
3382-
val = rb_Array(val);
3391+
if (NIL_P(val))
3392+
val = rb_ary_new2(0);
3393+
else
3394+
val = rb_ary_new3(1, val);
33833395
}
33843396
len = RARRAY(val)->len;
33853397
for (i=0; list && i<len; i++) {

0 commit comments

Comments
 (0)