Skip to content

Commit a1c02ee

Browse files
author
matz
committed
* 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
1 parent e60d556 commit a1c02ee

File tree

9 files changed

+112
-97
lines changed

9 files changed

+112
-97
lines changed

ChangeLog

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
Thu Nov 14 08:23:42 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
2+
3+
* math.c (math_acos): check errno after operation. ditto for
4+
asin, acosh, atanh, log, log10 and sqrt.
5+
6+
* eval.c (rb_add_method): initialize should always be private.
7+
8+
* parse.y (expr): add rescue modifier rule.
9+
10+
* parse.y (command_call): return, break and next with argument is
11+
now part of this rule.
12+
113
Wed Nov 13 16:22:38 2002 Nobuyoshi Nakada <nobu.nokada@softhome.net>
214

315
* configure.in (DLDFLAGS): removed -Wl,-no-undefined to
@@ -29,6 +41,11 @@ Sat Nov 9 11:39:45 2002 Nobuyoshi Nakada <nobu.nokada@softhome.net>
2941
* eval.c: remove ENABLE_TRACE/DISABLE_TRACE to trace child nodes of
3042
c-call. [ruby-dev:18699]
3143

44+
Fri Nov 8 04:16:55 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
45+
46+
* parse.y (yylex): "a" in "a /5" should be considered as a local
47+
variable. [experimental]
48+
3249
Thu Nov 7 09:51:37 2002 Nobuyoshi Nakada <nobu.nokada@softhome.net>
3350

3451
* eval.c (rb_yield_0): should enable trace for non-cfunc nodes.

MANIFEST

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,6 @@ missing/strerror.c
255255
missing/strftime.c
256256
missing/strncasecmp.c
257257
missing/strstr.c
258-
missing/strtod.c
259258
missing/strtol.c
260259
missing/strtoul.c
261260
missing/vsnprintf.c

configure.in

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -464,36 +464,6 @@ fi
464464
AC_FUNC_GETPGRP
465465
AC_FUNC_SETPGRP
466466

467-
AC_CACHE_CHECK(for working strtod, rb_cv_func_strtod,
468-
[AC_TRY_RUN([
469-
double strtod ();
470-
int
471-
main()
472-
{
473-
{
474-
/* Some versions of Linux strtod mis-parse strings with leading '+'. */
475-
char *string = " +69";
476-
char *term;
477-
double value;
478-
value = strtod(string, &term);
479-
if (value != 69 || term != (string + 4))
480-
exit(1);
481-
}
482-
483-
{
484-
/* Under Solaris 2.4, strtod returns the wrong value for the
485-
terminating character under some conditions. */
486-
char *string = "NaN";
487-
char *term;
488-
strtod(string, &term);
489-
if (term != string && *(term - 1) == 0)
490-
exit(1);
491-
}
492-
exit(0);
493-
}
494-
], rb_cv_func_strtod=yes, rb_cv_func_strtod=no, rb_cv_func_strtod=no)])
495-
test $rb_cv_func_strtod = no && AC_LIBOBJ([strtod])
496-
497467
AC_C_BIGENDIAN
498468
AC_C_CONST
499469
AC_C_CHAR_UNSIGNED

eval.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,10 @@ rb_clear_cache_by_class(klass)
230230
}
231231
}
232232

233+
static ID init, alloc, eqq, each, aref, aset, match, missing;
234+
static ID added, singleton_added;
235+
static ID __id__, __send__;
236+
233237
void
234238
rb_add_method(klass, mid, node, noex)
235239
VALUE klass;
@@ -243,6 +247,9 @@ rb_add_method(klass, mid, node, noex)
243247
if (ruby_safe_level >= 4 && (klass == rb_cObject || !OBJ_TAINTED(klass))) {
244248
rb_raise(rb_eSecurityError, "Insecure: can't define method");
245249
}
250+
if (mid == init) {
251+
noex = NOEX_PRIVATE | (noex & NOEX_NOSUPER);
252+
}
246253
if (OBJ_FROZEN(klass)) rb_error_frozen("class/module");
247254
rb_clear_cache_by_id(mid);
248255
body = NEW_METHOD(node, noex);
@@ -313,10 +320,6 @@ rb_get_method_body(klassp, idp, noexp)
313320
return body;
314321
}
315322

316-
static ID init, alloc, eqq, each, aref, aset, match, missing;
317-
static ID added, singleton_added;
318-
static ID __id__, __send__;
319-
320323
static void
321324
remove_method(klass, mid)
322325
VALUE klass;

lib/delegate.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
class Delegator
2020

2121
def initialize(obj)
22-
preserved = ::Kernel.instance_methods
22+
preserved = ::Kernel.public_instance_methods
2323
preserved -= ["to_s","to_a","inspect","==","=~","==="]
2424
for t in self.class.ancestors
25-
preserved |= t.instance_methods
25+
preserved |= t.public_instance_methods
2626
preserved |= t.private_instance_methods
2727
preserved |= t.protected_instance_methods
2828
break if t == Delegator
@@ -76,8 +76,8 @@ def __setobj__(obj)
7676
#
7777
def DelegateClass(superclass)
7878
klass = Class.new
79-
methods = superclass.instance_methods(true)
80-
methods -= ::Kernel.instance_methods
79+
methods = superclass.public_instance_methods(true)
80+
methods -= ::Kernel.public_instance_methods
8181
methods |= ["to_s","to_a","inspect","==","=~","==="]
8282
klass.module_eval <<-EOS
8383
def initialize(obj)

lib/pstore.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def transaction(read_only=false)
102102
file.flock(read_only ? File::LOCK_SH : File::LOCK_EX)
103103
if read_only
104104
@table = Marshal::load(file)
105-
elsif orig and (content = file.read) != nil
105+
elsif orig and (content = file.read) != ""
106106
@table = Marshal::load(content)
107107
size = content.size
108108
md5 = Digest::MD5.digest(content)
@@ -118,7 +118,7 @@ def transaction(read_only=false)
118118
@abort = true
119119
raise
120120
ensure
121-
if !read_only && !@abort
121+
if !read_only and !@abort
122122
file.rewind
123123
content = Marshal::dump(@table)
124124
if !md5 || size != content.size || md5 != Digest::MD5.digest(content)
@@ -133,6 +133,9 @@ def transaction(read_only=false)
133133
end
134134
end
135135
end
136+
if @abort and !orig
137+
File.unlink(@filename)
138+
end
136139
@abort = false
137140
end
138141
ensure

math.c

Lines changed: 58 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include "ruby.h"
1414
#include <math.h>
15+
#include <sys/errno.h>
1516

1617
VALUE rb_mMath;
1718

@@ -26,7 +27,6 @@ math_atan2(obj, y, x)
2627
VALUE obj, x, y;
2728
{
2829
Need_Float2(y, x);
29-
3030
return rb_float_new(atan2(RFLOAT(y)->value, RFLOAT(x)->value));
3131
}
3232

@@ -35,7 +35,6 @@ math_cos(obj, x)
3535
VALUE obj, x;
3636
{
3737
Need_Float(x);
38-
3938
return rb_float_new(cos(RFLOAT(x)->value));
4039
}
4140

@@ -61,32 +60,37 @@ static VALUE
6160
math_acos(obj, x)
6261
VALUE obj, x;
6362
{
63+
double d;
64+
6465
Need_Float(x);
65-
/*
66-
if (RFLOAT(x)->value < -1.0 || RFLOAT(x)->value > 1.0)
67-
rb_raise(rb_eArgError, "Out of range (-1..1)");
68-
*/
69-
return rb_float_new(acos(RFLOAT(x)->value));
66+
errno = 0;
67+
d = acos(RFLOAT(x)->value);
68+
if (errno) {
69+
rb_sys_fail("acos");
70+
}
71+
return rb_float_new(d);
7072
}
7173

7274
static VALUE
7375
math_asin(obj, x)
7476
VALUE obj, x;
7577
{
78+
double d;
79+
7680
Need_Float(x);
77-
/*
78-
if (RFLOAT(x)->value < -1.0 || RFLOAT(x)->value > 1.0)
79-
rb_raise(rb_eArgError, "Out of range (-1..1)");
80-
*/
81-
return rb_float_new(asin(RFLOAT(x)->value));
81+
errno = 0;
82+
d = asin(RFLOAT(x)->value);
83+
if (errno) {
84+
rb_sys_fail("asin");
85+
}
86+
return rb_float_new(d);
8287
}
8388

8489
static VALUE
8590
math_atan(obj, x)
8691
VALUE obj, x;
8792
{
8893
Need_Float(x);
89-
9094
return rb_float_new(atan(RFLOAT(x)->value));
9195
}
9296

@@ -122,7 +126,6 @@ math_sinh(obj, x)
122126
VALUE obj, x;
123127
{
124128
Need_Float(x);
125-
126129
return rb_float_new(sinh(RFLOAT(x)->value));
127130
}
128131

@@ -140,43 +143,52 @@ math_tanh(obj, x)
140143
VALUE obj, x;
141144
{
142145
Need_Float(x);
143-
144146
return rb_float_new(tanh(RFLOAT(x)->value));
145147
}
146148

147149
static VALUE
148150
math_acosh(obj, x)
149151
VALUE obj, x;
150152
{
153+
double d;
154+
151155
Need_Float(x);
152-
153-
return rb_float_new(acosh(RFLOAT(x)->value));
156+
errno = 0;
157+
d = acosh(RFLOAT(x)->value);
158+
if (errno) {
159+
rb_sys_fail("acosh");
160+
}
161+
return rb_float_new(d);
154162
}
155163

156164
static VALUE
157165
math_asinh(obj, x)
158166
VALUE obj, x;
159167
{
160168
Need_Float(x);
161-
162169
return rb_float_new(asinh(RFLOAT(x)->value));
163170
}
164171

165172
static VALUE
166173
math_atanh(obj, x)
167174
VALUE obj, x;
168175
{
176+
double d;
177+
169178
Need_Float(x);
170-
171-
return rb_float_new(atanh(RFLOAT(x)->value));
179+
errno = 0;
180+
d = atanh(RFLOAT(x)->value);
181+
if (errno) {
182+
rb_sys_fail("atanh");
183+
}
184+
return rb_float_new(d);
172185
}
173186

174187
static VALUE
175188
math_exp(obj, x)
176189
VALUE obj, x;
177190
{
178191
Need_Float(x);
179-
180192
return rb_float_new(exp(RFLOAT(x)->value));
181193
}
182194

@@ -189,28 +201,45 @@ static VALUE
189201
math_log(obj, x)
190202
VALUE obj, x;
191203
{
204+
double d;
205+
192206
Need_Float(x);
193-
194-
return rb_float_new(log(RFLOAT(x)->value));
207+
errno = 0;
208+
d = log(RFLOAT(x)->value);
209+
if (errno) {
210+
rb_sys_fail("log");
211+
}
212+
return rb_float_new(d);
195213
}
196214

197215
static VALUE
198216
math_log10(obj, x)
199217
VALUE obj, x;
200218
{
219+
double d;
220+
201221
Need_Float(x);
202-
203-
return rb_float_new(log10(RFLOAT(x)->value));
222+
errno = 0;
223+
d = log10(RFLOAT(x)->value);
224+
if (errno) {
225+
rb_sys_fail("log10");
226+
}
227+
return rb_float_new(d);
204228
}
205229

206230
static VALUE
207231
math_sqrt(obj, x)
208232
VALUE obj, x;
209233
{
210-
Need_Float(x);
234+
double d;
211235

212-
if (RFLOAT(x)->value < 0.0) rb_raise(rb_eArgError, "square root for negative number");
213-
return rb_float_new(sqrt(RFLOAT(x)->value));
236+
Need_Float(x);
237+
errno = 0;
238+
d = sqrt(RFLOAT(x)->value);
239+
if (errno) {
240+
rb_sys_fail("sqrt");
241+
}
242+
return rb_float_new(d);
214243
}
215244

216245
static VALUE
@@ -230,19 +259,15 @@ static VALUE
230259
math_ldexp(obj, x, n)
231260
VALUE obj, x, n;
232261
{
233-
double d;
234-
235262
Need_Float(x);
236-
237-
return rb_float_new(d = ldexp(RFLOAT(x)->value, NUM2INT(n)));
263+
return rb_float_new(ldexp(RFLOAT(x)->value, NUM2INT(n)));
238264
}
239265

240266
static VALUE
241267
math_hypot(obj, x, y)
242268
VALUE obj, x, y;
243269
{
244270
Need_Float2(x, y);
245-
246271
return rb_float_new(hypot(RFLOAT(x)->value, RFLOAT(y)->value));
247272
}
248273

missing.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,6 @@ extern size_t strftime _((char *, size_t, const char *, const struct tm *));
107107
extern char *strstr _((char *, char *));
108108
#endif
109109

110-
#ifndef HAVE_STRTOD
111-
extern double strtod _((const char *, char **));
112-
#endif
113-
114110
/*
115111
#ifndef HAVE_STRTOL
116112
extern long strtol _((char *, char **, int));

0 commit comments

Comments
 (0)