summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog7
-rw-r--r--include/ruby/intern.h1
-rw-r--r--object.c15
-rw-r--r--pack.c2
4 files changed, 24 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index c3cb8ac1f2..2cad5e9be3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Mon Dec 29 22:37:57 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * pack.c (pack_pack): template f should not accept non float
+ values. [ruby-dev:37656]
+
+ * object.c (rb_to_float): new function to type check floats.
+
Mon Dec 29 22:27:11 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
* random.c (rb_f_rand): type check simplified. strings are no
diff --git a/include/ruby/intern.h b/include/ruby/intern.h
index 9d69089733..38f44f94cd 100644
--- a/include/ruby/intern.h
+++ b/include/ruby/intern.h
@@ -434,6 +434,7 @@ VALUE rb_check_convert_type(VALUE,int,const char*,const char*);
VALUE rb_check_to_integer(VALUE, const char *);
VALUE rb_to_int(VALUE);
VALUE rb_Integer(VALUE);
+VALUE rb_to_float(VALUE);
VALUE rb_Float(VALUE);
VALUE rb_String(VALUE);
VALUE rb_Array(VALUE);
diff --git a/object.c b/object.c
index 4f2fcb6def..889a0c6d21 100644
--- a/object.c
+++ b/object.c
@@ -2267,6 +2267,21 @@ rb_f_float(VALUE obj, VALUE arg)
return rb_Float(arg);
}
+VALUE
+rb_to_float(VALUE val)
+{
+ VALUE v;
+
+ if (TYPE(val) == T_FLOAT) return val;
+ v = convert_type(val, "Float", "to_f", Qtrue);
+ if (TYPE(v) != T_FLOAT) {
+ const char *cname = rb_obj_classname(val);
+ rb_raise(rb_eTypeError, "can't convert %s to Float (%s#to_f gives %s)",
+ cname, cname, rb_obj_classname(v));
+ }
+ return v;
+}
+
double
rb_num2dbl(VALUE val)
{
diff --git a/pack.c b/pack.c
index 4f2533f2d6..077baff04b 100644
--- a/pack.c
+++ b/pack.c
@@ -789,7 +789,7 @@ pack_pack(VALUE ary, VALUE fmt)
float f;
from = NEXTFROM;
- f = RFLOAT_VALUE(rb_Float(from));
+ f = RFLOAT_VALUE(rb_to_float(from));
rb_str_buf_cat(res, (char*)&f, sizeof(float));
}
break;