From fe13785cc699692cefbdf94908fcaa7c99672f0f Mon Sep 17 00:00:00 2001 From: matz Date: Tue, 29 Jul 2003 18:26:55 +0000 Subject: [PATCH] * marshal.c (w_object): if object responds to 'marshal_dump', Marshal.dump uses it to dump object. unlike '_dump', marshal_dump returns any kind of object. * marshal.c (r_object0): restore instance by calling 'marshal_load' method. unlike '_load', it's an instance method, to handle cyclic reference. * marshal.c (marshal_load): all objects read from file should be tainted. [ruby-core:01325] * lib/timeout.rb (Timeout::timeout): execute immediately if sec is zero. * ext/socket/socket.c (socks_init): typo fixed. [ruby-talk:77232] * ext/socket/extconf.rb: the default value for --enable-socks is taken from ENV["SOCKS_SERVER"]. [ruby-talk:77232] * ruby.c (proc_options): add -W option. -W0 to shut up all warning messages. [ruby-talk:77227] * error.c (rb_warn): no message will be printed if the value of $VERBOSE is "nil", i.e. perfect silence. * ruby.c (verbose_setter): $VERBOSE value is either true, false, or nil. * io.c (Init_IO): no "read" check for $stdin. in addition some function names has been changed. * regex.c (re_match_exec): incorrect multibyte match. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4220 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 43 +++++++++++++++++++++++++++++++++++++++++++ error.c | 2 ++ ext/socket/extconf.rb | 2 +- ext/socket/socket.c | 2 +- io.c | 36 +++++++++++++----------------------- lib/timeout.rb | 8 +++++++- marshal.c | 34 ++++++++++++++++++++++++++++------ regex.c | 2 +- ruby.c | 37 ++++++++++++++++++++++++++++++++++--- 9 files changed, 130 insertions(+), 36 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5931c6f8b1..e614097a1a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,46 @@ +Wed Jul 30 02:37:12 2003 Yukihiro Matsumoto + + * marshal.c (w_object): if object responds to 'marshal_dump', + Marshal.dump uses it to dump object. unlike '_dump', + marshal_dump returns any kind of object. + + * marshal.c (r_object0): restore instance by calling + 'marshal_load' method. unlike '_load', it's an instance + method, to handle cyclic reference. + + * marshal.c (marshal_load): all objects read from file should be + tainted. [ruby-core:01325] + +Wed Jul 30 01:47:51 2003 Hugh Sasse + + * lib/timeout.rb (Timeout::timeout): execute immediately if sec is + zero. + +Wed Jul 30 01:36:18 2003 Aron Griffis + + * ext/socket/socket.c (socks_init): typo fixed. [ruby-talk:77232] + +Wed Jul 30 00:48:43 2003 Yukihiro Matsumoto + + * ext/socket/extconf.rb: the default value for --enable-socks is + taken from ENV["SOCKS_SERVER"]. [ruby-talk:77232] + + * ruby.c (proc_options): add -W option. -W0 to shut up all warning + messages. [ruby-talk:77227] + + * error.c (rb_warn): no message will be printed if the value of + $VERBOSE is "nil", i.e. perfect silence. + + * ruby.c (verbose_setter): $VERBOSE value is either true, false, + or nil. + + * io.c (Init_IO): no "read" check for $stdin. in addition some + function names has been changed. + +Tue Jul 29 23:10:19 2003 Yoshida Masato + + * regex.c (re_match_exec): incorrect multibyte match. + Tue Jul 29 22:36:50 2003 Minero Aoki * lib/net/smtp.rb (send0): do taint check only when $SAFE > 0 diff --git a/error.c b/error.c index bcc36d213a..fb900b26a4 100644 --- a/error.c +++ b/error.c @@ -129,6 +129,8 @@ rb_warn(fmt, va_alist) char buf[BUFSIZ]; va_list args; + if (NIL_P(ruby_verbose)) return; + snprintf(buf, BUFSIZ, "warning: %s", fmt); va_init_list(args, fmt); diff --git a/ext/socket/extconf.rb b/ext/socket/extconf.rb index c5489a9535..f72ac2ba42 100644 --- a/ext/socket/extconf.rb +++ b/ext/socket/extconf.rb @@ -359,7 +359,7 @@ if have_func(test_func) unless have_func("gethostname") have_func("uname") end - if ENV["SOCKS_SERVER"] or enable_config("socks", false) + if enable_config("socks", ENV["SOCKS_SERVER"]) if have_library("socks5", "SOCKSinit") $CFLAGS+=" -DSOCKS5 -DSOCKS" elsif have_library("socks", "Rconnect") diff --git a/ext/socket/socket.c b/ext/socket/socket.c index 9b1bf7fe39..5c78901772 100644 --- a/ext/socket/socket.c +++ b/ext/socket/socket.c @@ -1013,7 +1013,7 @@ socks_init(sock, host, serv) init = 1; } - return init_inetsock(class, host, serv, Qnil, Qnil, INET_SOCKS); + return init_inetsock(sock, host, serv, Qnil, Qnil, INET_SOCKS); } #ifdef SOCKS5 diff --git a/io.c b/io.c index 5243dd7e4f..454d0926b0 100644 --- a/io.c +++ b/io.c @@ -94,7 +94,7 @@ VALUE rb_cIO; VALUE rb_eEOFError; VALUE rb_eIOError; -VALUE rb_stdin, rb_stdout, rb_stderr, rb_defout; +VALUE rb_stdin, rb_stdout, rb_stderr; static VALUE orig_stdout, orig_stderr; VALUE rb_output_fs; @@ -2779,17 +2779,7 @@ must_respond_to(mid, val, id) } static void -set_input_var(val, id, variable) - VALUE val; - ID id; - VALUE *variable; -{ - must_respond_to(id_read, val, id); - *variable = val; -} - -static void -set_output_var(val, id, variable) +stdout_setter(val, id, variable) VALUE val; ID id; VALUE *variable; @@ -2799,22 +2789,22 @@ set_output_var(val, id, variable) } static void -set_defout_var(val, id, variable) +defout_setter(val, id, variable) VALUE val; ID id; VALUE *variable; { - set_output_var(val, id, variable); + stdout_setter(val, id, variable); rb_warn("$defout is obslete; use $stdout instead"); } static void -set_deferr_var(val, id, variable) +deferr_setter(val, id, variable) VALUE val; ID id; VALUE *variable; { - set_output_var(val, id, variable); + stdout_setter(val, id, variable); rb_warn("$deferr is obslete; use $stderr instead"); } @@ -4131,18 +4121,18 @@ Init_IO() rb_define_method(rb_cIO, "inspect", rb_io_inspect, 0); rb_stdin = prep_stdio(stdin, FMODE_READABLE, rb_cIO); - rb_define_hooked_variable("$stdin", &rb_stdin, 0, set_input_var); + rb_define_variable("$stdin", &rb_stdin); rb_stdout = prep_stdio(stdout, FMODE_WRITABLE, rb_cIO); - rb_define_hooked_variable("$stdout", &rb_stdout, 0, set_output_var); + rb_define_hooked_variable("$stdout", &rb_stdout, 0, stdout_setter); rb_stderr = prep_stdio(stderr, FMODE_WRITABLE, rb_cIO); - rb_define_hooked_variable("$stderr", &rb_stderr, 0, set_output_var); - rb_define_hooked_variable("$>", &rb_stdout, 0, set_output_var); - rb_defout = orig_stdout = rb_stdout; + rb_define_hooked_variable("$stderr", &rb_stderr, 0, stdout_setter); + rb_define_hooked_variable("$>", &rb_stdout, 0, stdout_setter); + orig_stdout = rb_stdout; orig_stderr = rb_stderr; /* variables to be removed in 1.8.1 */ - rb_define_hooked_variable("$defout", &rb_stdout, 0, set_defout_var); - rb_define_hooked_variable("$deferr", &rb_stderr, 0, set_deferr_var); + rb_define_hooked_variable("$defout", &rb_stdout, 0, defout_setter); + rb_define_hooked_variable("$deferr", &rb_stderr, 0, deferr_setter); /* constants to hold original stdin/stdout/stderr */ rb_define_global_const("STDIN", rb_stdin); diff --git a/lib/timeout.rb b/lib/timeout.rb index f5c4e3cbf0..5c6a72652a 100644 --- a/lib/timeout.rb +++ b/lib/timeout.rb @@ -34,7 +34,7 @@ module Timeout end def timeout(sec, exception=Error) - return yield if sec == nil + return yield if sec == nil or sec.zero? begin x = Thread.current y = Thread.start { @@ -63,6 +63,12 @@ if __FILE__ == $0 p timeout(5, TimeoutError) { 45 } + p timeout(nil) { + 54 + } + p timeout(0) { + 54 + } p timeout(5) { loop { p 10 diff --git a/marshal.c b/marshal.c index 4718f79209..14adf825c3 100644 --- a/marshal.c +++ b/marshal.c @@ -77,7 +77,7 @@ shortlen(len, ds) #define TYPE_IVAR 'I' #define TYPE_LINK '@' -static ID s_dump, s_load; +static ID s_dump, s_load, s_mdump, s_mload; static ID s_dump_data, s_load_data, s_alloc; static ID s_getc, s_read, s_write, s_binmode; @@ -480,14 +480,20 @@ w_object(obj, arg, limit) } st_add_direct(arg->data, obj, arg->data->num_entries); + if (rb_respond_to(obj, s_mdump)) { + VALUE v; + + v = rb_funcall(obj, s_mdump, 1, INT2NUM(limit)); + w_class(TYPE_USRMARSHAL, obj, arg); + w_object(v, arg, limit); + if (ivtbl) w_ivar(ivtbl, &c_arg); + return; + } if (rb_respond_to(obj, s_dump)) { VALUE v; - w_class(TYPE_USERDEF, obj, arg); v = rb_funcall(obj, s_dump, 1, INT2NUM(limit)); - if (TYPE(v) != T_STRING) { - rb_raise(rb_eTypeError, "_dump() must return String"); - } + w_class(TYPE_USERDEF, obj, arg); w_bytes(RSTRING(v)->ptr, RSTRING(v)->len, arg); if (ivtbl) w_ivar(ivtbl, &c_arg); return; @@ -1169,6 +1175,20 @@ r_object0(arg, proc) } break; + case TYPE_USRMARSHAL: + { + VALUE klass = path2class(r_unique(arg)); + + v = rb_obj_alloc(klass); + if (!rb_respond_to(v, s_mload)) { + rb_raise(rb_eTypeError, "instance of %s needs to have method `marshal_load'", + rb_class2name(klass)); + } + r_regist(v, arg); + rb_funcall(v, s_mload, 1, r_object(arg)); + } + break; + case TYPE_OBJECT: { VALUE klass = path2class(r_unique(arg)); @@ -1296,7 +1316,7 @@ marshal_load(argc, argv) if (rb_respond_to(port, s_binmode)) { rb_funcall2(port, s_binmode, 0, 0); } - arg.taint = Qfalse; + arg.taint = Qtrue; arg.ptr = (char *)port; arg.end = 0; } @@ -1333,6 +1353,8 @@ Init_marshal() s_dump = rb_intern("_dump"); s_load = rb_intern("_load"); + s_mdump = rb_intern("marshal_dump"); + s_mload = rb_intern("marshal_load"); s_dump_data = rb_intern("_dump_data"); s_load_data = rb_intern("_load_data"); s_alloc = rb_intern("_alloc"); diff --git a/regex.c b/regex.c index 6aff60cd9e..e9f382f0a4 100644 --- a/regex.c +++ b/regex.c @@ -3854,7 +3854,7 @@ re_match_exec(bufp, string_arg, size, pos, beg, regs) MBC2WC(c, d); not = is_in_list_mbc(c, p); if (!not) { - part = not = is_in_list(cc, p); + part = not = is_in_list_sbc(cc, p); } } else { not = is_in_list(c, p); diff --git a/ruby.c b/ruby.c index 0437b5bb04..21cdba182c 100644 --- a/ruby.c +++ b/ruby.c @@ -94,6 +94,7 @@ usage(name) "-T[level] turn on tainting checks", "-v print version number, then turn on verbose mode", "-w turn warnings on for your script", +"-W[level] set warning level; 0=silence, 1=medium, 3=verbose (default)", "-x[directory] strip off text before #!ruby line and perhaps cd to directory", "--copyright print the copyright", "--version print the version", @@ -480,6 +481,27 @@ proc_options(argc, argv) s++; goto reswitch; + case 'W': + { + int numlen; + int v = 2; /* -W as -W2 */ + + if (*++s) { + v = scan_oct(s, 1, &numlen); + if (numlen == 0) v = 1; + s += numlen; + } + switch (v) { + case 0: + ruby_verbose = Qnil; break; + case 1: + ruby_verbose = Qfalse; break; + default: + ruby_verbose = Qtrue; break; + } + } + goto reswitch; + case 'c': do_check = Qtrue; s++; @@ -1014,15 +1036,24 @@ forbid_setid(s) rb_raise(rb_eSecurityError, "No %s allowed in tainted mode", s); } +static void +verbose_setter(val, id, variable) + VALUE val; + ID id; + VALUE *variable; +{ + ruby_verbose = RTEST(val) ? Qtrue : val; +} + void ruby_prog_init() { init_ids(); ruby_sourcefile = rb_source_filename("ruby"); - rb_define_variable("$VERBOSE", &ruby_verbose); - rb_define_variable("$-v", &ruby_verbose); - rb_define_variable("$-w", &ruby_verbose); + rb_define_hooked_variable("$VERBOSE", &ruby_verbose, 0, verbose_setter); + rb_define_hooked_variable("$-v", &ruby_verbose, 0, verbose_setter); + rb_define_hooked_variable("$-w", &ruby_verbose, 0, verbose_setter); rb_define_variable("$DEBUG", &ruby_debug); rb_define_variable("$-d", &ruby_debug); rb_define_readonly_variable("$-p", &do_print);