From a1c02ee495d945f943fedc3f11fcb323289dc756 Mon Sep 17 00:00:00 2001 From: matz Date: Thu, 14 Nov 2002 06:18:59 +0000 Subject: * math.c (math_acos): check errno after operation. ditto for asin, acosh, atanh, log, log10 and sqrt. * eval.c (rb_add_method): initialize should always be private. * parse.y (expr): add rescue modifier rule. * parse.y (command_call): return, break and next with argument is now part of this rule. * parse.y (yylex): "a" in "a /5" should be considered as a local variable. [experimental] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3041 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 17 +++++++++++ MANIFEST | 1 - configure.in | 30 ------------------- eval.c | 11 ++++--- lib/delegate.rb | 8 ++--- lib/pstore.rb | 7 +++-- math.c | 91 ++++++++++++++++++++++++++++++++++++--------------------- missing.h | 4 --- parse.y | 40 +++++++++++++------------ 9 files changed, 112 insertions(+), 97 deletions(-) diff --git a/ChangeLog b/ChangeLog index 93eadaeefa..732a36c88a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +Thu Nov 14 08:23:42 2002 Yukihiro Matsumoto + + * math.c (math_acos): check errno after operation. ditto for + asin, acosh, atanh, log, log10 and sqrt. + + * eval.c (rb_add_method): initialize should always be private. + + * parse.y (expr): add rescue modifier rule. + + * parse.y (command_call): return, break and next with argument is + now part of this rule. + Wed Nov 13 16:22:38 2002 Nobuyoshi Nakada * configure.in (DLDFLAGS): removed -Wl,-no-undefined to @@ -29,6 +41,11 @@ Sat Nov 9 11:39:45 2002 Nobuyoshi Nakada * eval.c: remove ENABLE_TRACE/DISABLE_TRACE to trace child nodes of c-call. [ruby-dev:18699] +Fri Nov 8 04:16:55 2002 Yukihiro Matsumoto + + * parse.y (yylex): "a" in "a /5" should be considered as a local + variable. [experimental] + Thu Nov 7 09:51:37 2002 Nobuyoshi Nakada * eval.c (rb_yield_0): should enable trace for non-cfunc nodes. diff --git a/MANIFEST b/MANIFEST index 88b4460e88..a090181de1 100644 --- a/MANIFEST +++ b/MANIFEST @@ -255,7 +255,6 @@ missing/strerror.c missing/strftime.c missing/strncasecmp.c missing/strstr.c -missing/strtod.c missing/strtol.c missing/strtoul.c missing/vsnprintf.c diff --git a/configure.in b/configure.in index 1ed61aba9d..7397bf9837 100644 --- a/configure.in +++ b/configure.in @@ -464,36 +464,6 @@ fi AC_FUNC_GETPGRP AC_FUNC_SETPGRP -AC_CACHE_CHECK(for working strtod, rb_cv_func_strtod, -[AC_TRY_RUN([ -double strtod (); -int -main() -{ - { - /* Some versions of Linux strtod mis-parse strings with leading '+'. */ - char *string = " +69"; - char *term; - double value; - value = strtod(string, &term); - if (value != 69 || term != (string + 4)) - exit(1); - } - - { - /* Under Solaris 2.4, strtod returns the wrong value for the - terminating character under some conditions. */ - char *string = "NaN"; - char *term; - strtod(string, &term); - if (term != string && *(term - 1) == 0) - exit(1); - } - exit(0); -} -], rb_cv_func_strtod=yes, rb_cv_func_strtod=no, rb_cv_func_strtod=no)]) -test $rb_cv_func_strtod = no && AC_LIBOBJ([strtod]) - AC_C_BIGENDIAN AC_C_CONST AC_C_CHAR_UNSIGNED diff --git a/eval.c b/eval.c index 615df9c36a..3e9548d757 100644 --- a/eval.c +++ b/eval.c @@ -230,6 +230,10 @@ rb_clear_cache_by_class(klass) } } +static ID init, alloc, eqq, each, aref, aset, match, missing; +static ID added, singleton_added; +static ID __id__, __send__; + void rb_add_method(klass, mid, node, noex) VALUE klass; @@ -243,6 +247,9 @@ rb_add_method(klass, mid, node, noex) if (ruby_safe_level >= 4 && (klass == rb_cObject || !OBJ_TAINTED(klass))) { rb_raise(rb_eSecurityError, "Insecure: can't define method"); } + if (mid == init) { + noex = NOEX_PRIVATE | (noex & NOEX_NOSUPER); + } if (OBJ_FROZEN(klass)) rb_error_frozen("class/module"); rb_clear_cache_by_id(mid); body = NEW_METHOD(node, noex); @@ -313,10 +320,6 @@ rb_get_method_body(klassp, idp, noexp) return body; } -static ID init, alloc, eqq, each, aref, aset, match, missing; -static ID added, singleton_added; -static ID __id__, __send__; - static void remove_method(klass, mid) VALUE klass; diff --git a/lib/delegate.rb b/lib/delegate.rb index afd6a2abe8..707bc2144b 100644 --- a/lib/delegate.rb +++ b/lib/delegate.rb @@ -19,10 +19,10 @@ class Delegator def initialize(obj) - preserved = ::Kernel.instance_methods + preserved = ::Kernel.public_instance_methods preserved -= ["to_s","to_a","inspect","==","=~","==="] for t in self.class.ancestors - preserved |= t.instance_methods + preserved |= t.public_instance_methods preserved |= t.private_instance_methods preserved |= t.protected_instance_methods break if t == Delegator @@ -76,8 +76,8 @@ SimpleDelegater = SimpleDelegator # def DelegateClass(superclass) klass = Class.new - methods = superclass.instance_methods(true) - methods -= ::Kernel.instance_methods + methods = superclass.public_instance_methods(true) + methods -= ::Kernel.public_instance_methods methods |= ["to_s","to_a","inspect","==","=~","==="] klass.module_eval <<-EOS def initialize(obj) diff --git a/lib/pstore.rb b/lib/pstore.rb index dfec76e470..dd74f4fc2f 100644 --- a/lib/pstore.rb +++ b/lib/pstore.rb @@ -102,7 +102,7 @@ class PStore file.flock(read_only ? File::LOCK_SH : File::LOCK_EX) if read_only @table = Marshal::load(file) - elsif orig and (content = file.read) != nil + elsif orig and (content = file.read) != "" @table = Marshal::load(content) size = content.size md5 = Digest::MD5.digest(content) @@ -118,7 +118,7 @@ class PStore @abort = true raise ensure - if !read_only && !@abort + if !read_only and !@abort file.rewind content = Marshal::dump(@table) if !md5 || size != content.size || md5 != Digest::MD5.digest(content) @@ -133,6 +133,9 @@ class PStore end end end + if @abort and !orig + File.unlink(@filename) + end @abort = false end ensure diff --git a/math.c b/math.c index 153c5b7f0e..163efde2ef 100644 --- a/math.c +++ b/math.c @@ -12,6 +12,7 @@ #include "ruby.h" #include +#include VALUE rb_mMath; @@ -26,7 +27,6 @@ math_atan2(obj, y, x) VALUE obj, x, y; { Need_Float2(y, x); - return rb_float_new(atan2(RFLOAT(y)->value, RFLOAT(x)->value)); } @@ -35,7 +35,6 @@ math_cos(obj, x) VALUE obj, x; { Need_Float(x); - return rb_float_new(cos(RFLOAT(x)->value)); } @@ -61,24 +60,30 @@ static VALUE math_acos(obj, x) VALUE obj, x; { + double d; + Need_Float(x); - /* - if (RFLOAT(x)->value < -1.0 || RFLOAT(x)->value > 1.0) - rb_raise(rb_eArgError, "Out of range (-1..1)"); - */ - return rb_float_new(acos(RFLOAT(x)->value)); + errno = 0; + d = acos(RFLOAT(x)->value); + if (errno) { + rb_sys_fail("acos"); + } + return rb_float_new(d); } static VALUE math_asin(obj, x) VALUE obj, x; { + double d; + Need_Float(x); - /* - if (RFLOAT(x)->value < -1.0 || RFLOAT(x)->value > 1.0) - rb_raise(rb_eArgError, "Out of range (-1..1)"); - */ - return rb_float_new(asin(RFLOAT(x)->value)); + errno = 0; + d = asin(RFLOAT(x)->value); + if (errno) { + rb_sys_fail("asin"); + } + return rb_float_new(d); } static VALUE @@ -86,7 +91,6 @@ math_atan(obj, x) VALUE obj, x; { Need_Float(x); - return rb_float_new(atan(RFLOAT(x)->value)); } @@ -122,7 +126,6 @@ math_sinh(obj, x) VALUE obj, x; { Need_Float(x); - return rb_float_new(sinh(RFLOAT(x)->value)); } @@ -140,7 +143,6 @@ math_tanh(obj, x) VALUE obj, x; { Need_Float(x); - return rb_float_new(tanh(RFLOAT(x)->value)); } @@ -148,9 +150,15 @@ static VALUE math_acosh(obj, x) VALUE obj, x; { + double d; + Need_Float(x); - - return rb_float_new(acosh(RFLOAT(x)->value)); + errno = 0; + d = acosh(RFLOAT(x)->value); + if (errno) { + rb_sys_fail("acosh"); + } + return rb_float_new(d); } static VALUE @@ -158,7 +166,6 @@ math_asinh(obj, x) VALUE obj, x; { Need_Float(x); - return rb_float_new(asinh(RFLOAT(x)->value)); } @@ -166,9 +173,15 @@ static VALUE math_atanh(obj, x) VALUE obj, x; { + double d; + Need_Float(x); - - return rb_float_new(atanh(RFLOAT(x)->value)); + errno = 0; + d = atanh(RFLOAT(x)->value); + if (errno) { + rb_sys_fail("atanh"); + } + return rb_float_new(d); } static VALUE @@ -176,7 +189,6 @@ math_exp(obj, x) VALUE obj, x; { Need_Float(x); - return rb_float_new(exp(RFLOAT(x)->value)); } @@ -189,28 +201,45 @@ static VALUE math_log(obj, x) VALUE obj, x; { + double d; + Need_Float(x); - - return rb_float_new(log(RFLOAT(x)->value)); + errno = 0; + d = log(RFLOAT(x)->value); + if (errno) { + rb_sys_fail("log"); + } + return rb_float_new(d); } static VALUE math_log10(obj, x) VALUE obj, x; { + double d; + Need_Float(x); - - return rb_float_new(log10(RFLOAT(x)->value)); + errno = 0; + d = log10(RFLOAT(x)->value); + if (errno) { + rb_sys_fail("log10"); + } + return rb_float_new(d); } static VALUE math_sqrt(obj, x) VALUE obj, x; { - Need_Float(x); + double d; - if (RFLOAT(x)->value < 0.0) rb_raise(rb_eArgError, "square root for negative number"); - return rb_float_new(sqrt(RFLOAT(x)->value)); + Need_Float(x); + errno = 0; + d = sqrt(RFLOAT(x)->value); + if (errno) { + rb_sys_fail("sqrt"); + } + return rb_float_new(d); } static VALUE @@ -230,11 +259,8 @@ static VALUE math_ldexp(obj, x, n) VALUE obj, x, n; { - double d; - Need_Float(x); - - return rb_float_new(d = ldexp(RFLOAT(x)->value, NUM2INT(n))); + return rb_float_new(ldexp(RFLOAT(x)->value, NUM2INT(n))); } static VALUE @@ -242,7 +268,6 @@ math_hypot(obj, x, y) VALUE obj, x, y; { Need_Float2(x, y); - return rb_float_new(hypot(RFLOAT(x)->value, RFLOAT(y)->value)); } diff --git a/missing.h b/missing.h index 44e5f86cb9..0649113707 100644 --- a/missing.h +++ b/missing.h @@ -107,10 +107,6 @@ extern size_t strftime _((char *, size_t, const char *, const struct tm *)); extern char *strstr _((char *, char *)); #endif -#ifndef HAVE_STRTOD -extern double strtod _((const char *, char **)); -#endif - /* #ifndef HAVE_STRTOL extern long strtol _((char *, char **, int)); diff --git a/parse.y b/parse.y index c4335091af..5b8417f51f 100644 --- a/parse.y +++ b/parse.y @@ -555,19 +555,7 @@ stmt : kALIAS fitem {lex_state = EXPR_FNAME;} fitem | expr ; -expr : kRETURN call_args - { - $$ = NEW_RETURN(ret_args($2)); - } - | kBREAK call_args - { - $$ = NEW_BREAK(ret_args($2)); - } - | kNEXT call_args - { - $$ = NEW_NEXT(ret_args($2)); - } - | command_call +expr : command_call | expr kAND expr { $$ = logop(NODE_AND, $1, $3); @@ -584,6 +572,7 @@ expr : kRETURN call_args { $$ = NEW_NOT(cond($2)); } + | arg kRESCUE_MOD command_call | arg ; @@ -596,6 +585,18 @@ expr_value : expr command_call : command | block_command + | kRETURN call_args + { + $$ = NEW_RETURN(ret_args($2)); + } + | kBREAK call_args + { + $$ = NEW_BREAK(ret_args($2)); + } + | kNEXT call_args + { + $$ = NEW_NEXT(ret_args($2)); + } ; block_command : block_call @@ -3129,10 +3130,6 @@ arg_ambiguous() rb_warning("ambiguous first argument; make sure"); } -#if !defined(strtod) && !defined(HAVE_STDLIB_H) -double strtod (); -#endif - #define IS_ARG() (lex_state == EXPR_ARG || lex_state == EXPR_CMDARG) static int @@ -4251,10 +4248,12 @@ yylex() lex_state == EXPR_DOT || lex_state == EXPR_ARG || lex_state == EXPR_CMDARG) { - if (cmd_state) + if (cmd_state) { lex_state = EXPR_CMDARG; - else + } + else { lex_state = EXPR_ARG; + } } else { lex_state = EXPR_END; @@ -4269,6 +4268,9 @@ yylex() return -1; } last_id = yylval.id = rb_intern(tok()); + if ((dyna_in_block() && rb_dvar_defined(last_id)) || local_id(last_id)) { + lex_state = EXPR_END; + } return result; } } -- cgit v1.2.3