1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7077 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2004-10-19 19:17:33 +00:00
parent b9ec9b69a9
commit 9f6b3edcd6
6 changed files with 78 additions and 21 deletions

View file

@ -1,3 +1,16 @@
Wed Oct 20 01:37:18 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* 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 <nobu@ruby-lang.org> Wed Oct 20 00:25:41 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* eval.c (search_required): required name must not be changed before * eval.c (search_required): required name must not be changed before

View file

@ -2506,7 +2506,7 @@ rb_ary_times(ary, times)
} }
len = NUM2LONG(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) { if (len < 0) {
rb_raise(rb_eArgError, "negative argument"); rb_raise(rb_eArgError, "negative argument");
} }

57
eval.c
View file

@ -1444,13 +1444,11 @@ extern NODE *ruby_eval_tree;
static void cont_call _((VALUE)); static void cont_call _((VALUE));
int static int
ruby_exec() ruby_exec_internal()
{ {
int state; int state;
volatile NODE *tmp;
Init_stack((void*)&tmp);
PUSH_TAG(PROT_THREAD); PUSH_TAG(PROT_THREAD);
PUSH_ITER(ITER_NOT); PUSH_ITER(ITER_NOT);
/* default visibility is private at toplevel */ /* default visibility is private at toplevel */
@ -1468,6 +1466,15 @@ ruby_exec()
return state; return state;
} }
int
ruby_exec()
{
volatile NODE *tmp;
Init_stack((void*)&tmp);
return ruby_exec_internal();
}
void void
ruby_stop(ex) ruby_stop(ex)
int 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 * MISSING: documentation
*/ */
@ -7791,15 +7813,25 @@ proc_clone(self)
Data_Get_Struct(self, struct BLOCK, orig); Data_Get_Struct(self, struct BLOCK, orig);
bind = Data_Make_Struct(rb_obj_class(self),struct BLOCK,blk_mark,blk_free,data); bind = Data_Make_Struct(rb_obj_class(self),struct BLOCK,blk_mark,blk_free,data);
CLONESETUP(bind, self); CLONESETUP(bind, self);
MEMCPY(data, orig, struct BLOCK, 1); blk_dup(data, orig);
frame_dup(&data->frame);
if (data->iter) { return bind;
blk_copy_prev(data); }
}
else { /*
data->prev = 0; * 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; return bind;
} }
@ -9224,6 +9256,7 @@ Init_Proc()
rb_define_singleton_method(rb_cProc, "new", proc_s_new, -1); 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, "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, "call", proc_call, -2);
rb_define_method(rb_cProc, "arity", proc_arity, 0); rb_define_method(rb_cProc, "arity", proc_arity, 0);
rb_define_method(rb_cProc, "[]", proc_call, -2); rb_define_method(rb_cProc, "[]", proc_call, -2);

View file

@ -285,6 +285,8 @@ bsock_setsockopt(sock, lev, optname, val)
rb_secure(2); rb_secure(2);
level = NUM2INT(lev); level = NUM2INT(lev);
option = NUM2INT(optname); option = NUM2INT(optname);
GetOpenFile(sock, fptr);
switch (TYPE(val)) { switch (TYPE(val)) {
case T_FIXNUM: case T_FIXNUM:
i = FIX2INT(val); i = FIX2INT(val);
@ -304,7 +306,6 @@ bsock_setsockopt(sock, lev, optname, val)
break; break;
} }
GetOpenFile(sock, fptr);
if (setsockopt(fileno(fptr->f), level, option, v, vlen) < 0) if (setsockopt(fileno(fptr->f), level, option, v, vlen) < 0)
rb_sys_fail(fptr->path); rb_sys_fail(fptr->path);
@ -2182,7 +2183,7 @@ sock_s_gethostbyaddr(argc, argv)
t = AF_INET6; t = AF_INET6;
} }
#endif #endif
h = gethostbyaddr((char*)RSTRING(addr)->ptr, RSTRING(addr)->len, t); h = gethostbyaddr(RSTRING(addr)->ptr, RSTRING(addr)->len, t);
if (h == NULL) { if (h == NULL) {
#ifdef HAVE_HSTRERROR #ifdef HAVE_HSTRERROR
extern int h_errno; extern int h_errno;
@ -2223,14 +2224,15 @@ sock_s_getservbyaname(argc, argv)
rb_scan_args(argc, argv, "11", &service, &proto); rb_scan_args(argc, argv, "11", &service, &proto);
if (NIL_P(proto)) proto = rb_str_new2("tcp"); 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) { if (sp) {
port = ntohs(sp->s_port); port = ntohs(sp->s_port);
} }
else { else {
char *s = StringValuePtr(service); char *s = RSTRING(service)->ptr;
char *end; char *end;
port = strtoul(s, &end, 0); port = strtoul(s, &end, 0);

View file

@ -532,6 +532,7 @@ zstream_detach_buffer(z)
z->buf_filled = 0; z->buf_filled = 0;
z->stream.next_out = 0; z->stream.next_out = 0;
z->stream.avail_out = 0; z->stream.avail_out = 0;
RBASIC(dst)->klass = rb_cString;
return dst; return dst;
} }

View file

@ -76,10 +76,14 @@ class SimpleDelegator<Delegator
@_sd_obj = obj @_sd_obj = obj
end end
def initialize_copy(obj) def clone(obj)
super super
__setobj__(obj.__getobj__.clone) __setobj__(obj.__getobj__.clone)
end end
def dup(obj)
super
__setobj__(obj.__getobj__.dup)
end
end end
# backward compatibility ^_^;;; # backward compatibility ^_^;;;
@ -108,9 +112,13 @@ def DelegateClass(superclass)
def __setobj__(obj) def __setobj__(obj)
@_dc_obj = obj @_dc_obj = obj
end end
def initialize_copy(obj) def clone(obj)
super super
__setobj__(obj.__getobj__.clone) __setobj__(obj.__getobj__.clone)
end
def dup(obj)
super
__setobj__(obj.__getobj__.dup)
end end
} }
for method in methods for method in methods