Revision
4421
Author
lsansonetti@apple.com
Date
2010-08-10 18:55:41 -0700 (Tue, 10 Aug 2010)

Log Message

when trying to convert a string into a numeric type, raise an exception in case the string encoding isn't ASCII incompatible

Modified Paths

Diff

Modified: MacRuby/trunk/bignum.c (4420 => 4421)


--- MacRuby/trunk/bignum.c	2010-08-11 01:54:56 UTC (rev 4420)
+++ MacRuby/trunk/bignum.c	2010-08-11 01:55:41 UTC (rev 4421)
@@ -12,6 +12,7 @@
 #include "ruby/macruby.h"
 
 #include "objc.h"
+#include "encoding.h"
 
 #include <math.h>
 #include <float.h>
@@ -593,6 +594,7 @@
     long len;
 
     StringValue(str);
+    str_check_ascii_compatible(str);
     if (badcheck) {
 	s = StringValueCStr(str);
     }

Modified: MacRuby/trunk/encoding.h (4420 => 4421)


--- MacRuby/trunk/encoding.h	2010-08-11 01:54:56 UTC (rev 4420)
+++ MacRuby/trunk/encoding.h	2010-08-11 01:55:41 UTC (rev 4421)
@@ -359,6 +359,14 @@
 rb_str_t *replacement_string_for_encoding(rb_encoding_t* enc);
 void str_replace_with_string(rb_str_t *self, rb_str_t *source);
 
+static inline void
+str_check_ascii_compatible(VALUE str)
+{
+    if (IS_RSTR(str) && !RSTR(str)->encoding->ascii_compatible) {
+	rb_raise(rb_eEncCompatError, "ASCII incompatible encoding: %s",
+		RSTR(str)->encoding->public_name);
+    }
+}
 
 #if defined(__cplusplus)
 } // extern "C"