diff --git a/ChangeLog b/ChangeLog index 0474f92093..8dd2cac35e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +Wed Oct 20 01:37:18 2004 Yukihiro Matsumoto + + * array.c (rb_ary_times): Array#* should return an instance of + the class of right operand. [ruby-dev:24526] + + * ext/zlib/zlib.c (zstream_detach_buffer): should not expose + class-less object to Ruby world. [ruby-dev:24530] + + * eval.c (proc_dup): provide Proc#dup as well. [ruby-talk:116915] + + * eval.c (ruby_exec): stack marking position may be higher than + expected. thanks to Guy Decoux. [ruby-core:03527] + Wed Oct 20 00:25:41 2004 Nobuyoshi Nakada * eval.c (search_required): required name must not be changed before diff --git a/array.c b/array.c index 37f21f6d3b..a285f8a183 100644 --- a/array.c +++ b/array.c @@ -2506,7 +2506,7 @@ rb_ary_times(ary, times) } len = NUM2LONG(times); - if (len == 0) return rb_ary_new2(0); + if (len == 0) return ary_new(rb_obj_class(ary), 0); if (len < 0) { rb_raise(rb_eArgError, "negative argument"); } diff --git a/eval.c b/eval.c index 81d380eb84..e9b720b67d 100644 --- a/eval.c +++ b/eval.c @@ -1444,13 +1444,11 @@ extern NODE *ruby_eval_tree; static void cont_call _((VALUE)); -int -ruby_exec() +static int +ruby_exec_internal() { int state; - volatile NODE *tmp; - Init_stack((void*)&tmp); PUSH_TAG(PROT_THREAD); PUSH_ITER(ITER_NOT); /* default visibility is private at toplevel */ @@ -1468,6 +1466,15 @@ ruby_exec() return state; } +int +ruby_exec() +{ + volatile NODE *tmp; + + Init_stack((void*)&tmp); + return ruby_exec_internal(); +} + void ruby_stop(ex) int ex; @@ -7777,6 +7784,21 @@ blk_copy_prev(block) } +static void +blk_dup(dup, orig) + struct BLOCK *dup, *orig; +{ + MEMCPY(dup, orig, struct BLOCK, 1); + frame_dup(&dup->frame); + + if (dup->iter) { + blk_copy_prev(dup); + } + else { + dup->prev = 0; + } +} + /* * MISSING: documentation */ @@ -7791,15 +7813,25 @@ proc_clone(self) Data_Get_Struct(self, struct BLOCK, orig); bind = Data_Make_Struct(rb_obj_class(self),struct BLOCK,blk_mark,blk_free,data); CLONESETUP(bind, self); - MEMCPY(data, orig, struct BLOCK, 1); - frame_dup(&data->frame); + blk_dup(data, orig); - if (data->iter) { - blk_copy_prev(data); - } - else { - data->prev = 0; - } + return bind; +} + +/* + * MISSING: documentation + */ + +static VALUE +proc_dup(self) + VALUE self; +{ + struct BLOCK *orig, *data; + VALUE bind; + + Data_Get_Struct(self, struct BLOCK, orig); + bind = Data_Make_Struct(rb_obj_class(self),struct BLOCK,blk_mark,blk_free,data); + blk_dup(data, orig); return bind; } @@ -9224,6 +9256,7 @@ Init_Proc() rb_define_singleton_method(rb_cProc, "new", proc_s_new, -1); rb_define_method(rb_cProc, "clone", proc_clone, 0); + rb_define_method(rb_cProc, "dup", proc_dup, 0); rb_define_method(rb_cProc, "call", proc_call, -2); rb_define_method(rb_cProc, "arity", proc_arity, 0); rb_define_method(rb_cProc, "[]", proc_call, -2); diff --git a/ext/socket/socket.c b/ext/socket/socket.c index 044d411b29..5c57f2e1f1 100644 --- a/ext/socket/socket.c +++ b/ext/socket/socket.c @@ -285,6 +285,8 @@ bsock_setsockopt(sock, lev, optname, val) rb_secure(2); level = NUM2INT(lev); option = NUM2INT(optname); + GetOpenFile(sock, fptr); + switch (TYPE(val)) { case T_FIXNUM: i = FIX2INT(val); @@ -304,7 +306,6 @@ bsock_setsockopt(sock, lev, optname, val) break; } - GetOpenFile(sock, fptr); if (setsockopt(fileno(fptr->f), level, option, v, vlen) < 0) rb_sys_fail(fptr->path); @@ -2182,7 +2183,7 @@ sock_s_gethostbyaddr(argc, argv) t = AF_INET6; } #endif - h = gethostbyaddr((char*)RSTRING(addr)->ptr, RSTRING(addr)->len, t); + h = gethostbyaddr(RSTRING(addr)->ptr, RSTRING(addr)->len, t); if (h == NULL) { #ifdef HAVE_HSTRERROR extern int h_errno; @@ -2223,14 +2224,15 @@ sock_s_getservbyaname(argc, argv) rb_scan_args(argc, argv, "11", &service, &proto); if (NIL_P(proto)) proto = rb_str_new2("tcp"); - else StringValue(proto); + StringValue(service); + StringValue(proto); - sp = getservbyname((char*)RSTRING(service)->ptr, RSTRING(proto)->ptr); + sp = getservbyname(StringValueCStr(service), StringValueCStr(proto)); if (sp) { port = ntohs(sp->s_port); } else { - char *s = StringValuePtr(service); + char *s = RSTRING(service)->ptr; char *end; port = strtoul(s, &end, 0); diff --git a/ext/zlib/zlib.c b/ext/zlib/zlib.c index 9d1b204eb7..f5fe2e3fa4 100644 --- a/ext/zlib/zlib.c +++ b/ext/zlib/zlib.c @@ -532,6 +532,7 @@ zstream_detach_buffer(z) z->buf_filled = 0; z->stream.next_out = 0; z->stream.avail_out = 0; + RBASIC(dst)->klass = rb_cString; return dst; } diff --git a/lib/delegate.rb b/lib/delegate.rb index c6f8f5d946..10b135116d 100644 --- a/lib/delegate.rb +++ b/lib/delegate.rb @@ -76,10 +76,14 @@ class SimpleDelegator