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

* 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
This commit is contained in:
matz 2003-07-29 18:26:55 +00:00
parent 7d1de7464b
commit fe13785cc6
9 changed files with 130 additions and 36 deletions

View file

@ -1,3 +1,46 @@
Wed Jul 30 02:37:12 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
* 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 <hgs@dmu.ac.uk>
* lib/timeout.rb (Timeout::timeout): execute immediately if sec is
zero.
Wed Jul 30 01:36:18 2003 Aron Griffis <ruby-talk@griffis1.net>
* ext/socket/socket.c (socks_init): typo fixed. [ruby-talk:77232]
Wed Jul 30 00:48:43 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
* 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 <yoshidam@yoshidam.net>
* regex.c (re_match_exec): incorrect multibyte match.
Tue Jul 29 22:36:50 2003 Minero Aoki <aamine@loveruby.net>
* lib/net/smtp.rb (send0): do taint check only when $SAFE > 0

View file

@ -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);

View file

@ -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")

View file

@ -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

36
io.c
View file

@ -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);

View file

@ -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

View file

@ -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");

View file

@ -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);

37
ruby.c
View file

@ -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);