[macruby-changes] [4421] MacRuby/trunk

source_changes at macosforge.org source_changes at macosforge.org
Tue Aug 10 18:55:42 PDT 2010


Revision: 4421
          http://trac.macosforge.org/projects/ruby/changeset/4421
Author:   lsansonetti at 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:
--------------
    MacRuby/trunk/bignum.c
    MacRuby/trunk/encoding.h

Modified: MacRuby/trunk/bignum.c
===================================================================
--- 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
===================================================================
--- 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"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20100810/3eb8c4ba/attachment.html>


More information about the macruby-changes mailing list