[macruby-changes] [234] MacRuby/trunk

source_changes at macosforge.org source_changes at macosforge.org
Wed May 28 16:51:41 PDT 2008


Revision: 234
          http://trac.macosforge.org/projects/ruby/changeset/234
Author:   lsansonetti at apple.com
Date:     2008-05-28 16:51:40 -0700 (Wed, 28 May 2008)

Log Message:
-----------
fix for #65, misc cleanup

Modified Paths:
--------------
    MacRuby/trunk/objc.m
    MacRuby/trunk/string.c
    MacRuby/trunk/test/ruby/test_string.rb

Modified: MacRuby/trunk/objc.m
===================================================================
--- MacRuby/trunk/objc.m	2008-05-28 20:03:03 UTC (rev 233)
+++ MacRuby/trunk/objc.m	2008-05-28 23:51:40 UTC (rev 234)
@@ -400,37 +400,7 @@
     return NULL;
 }
 
-#if 0
 static bool
-rb_primitive_obj_to_ocid(VALUE rval, id *ocval)
-{
-    if (TYPE(rval) == T_STRING) {
-	CFStringRef string;
-	CFStringEncoding cf_encoding;	
-	rb_encoding *enc;
-
-	enc = rb_enc_get(rval);
-	if (enc == NULL) {
-	    cf_encoding = kCFStringEncodingASCII;
-	}
-	else {
-	    /* TODO: support more encodings! */
-	    cf_encoding = kCFStringEncodingASCII;
-	}
-
-	string = CFStringCreateWithCStringNoCopy(
-	    NULL, RSTRING_PTR(rval), cf_encoding, kCFAllocatorNull);
-
-	*ocval = NSMakeCollectable(string);
-	return true;
-    }
-
-    rb_bug("cannot convert primitive obj `%s' to Objective-C",
-	   RSTRING_PTR(rb_inspect(rval)));
-}
-#endif
-
-static bool
 rb_objc_rval_to_ocid(VALUE rval, void **ocval)
 {
     if (!rb_special_const_p(rval) && rb_objc_is_non_native(rval)) {
@@ -568,9 +538,6 @@
 		val = rb_ivar_get(rval, ivar_id);
 		snprintf(buf, sizeof buf, "%s=", bs_struct->fields[i].name);
 		rb_funcall(rval, rb_intern(buf), 1, val);
-
-		//if (clean_ivars)
-		  //  rb_rval_remove_instance_variable(rval, ID2SYM(ivar_id));
 	    }
 	}
     }
@@ -645,6 +612,7 @@
 
     if (st_lookup(bs_boxeds, (st_data_t)octype, (st_data_t *)&bs_boxed)) {
 	void *data;
+
 	if (TYPE(rval) == T_ARRAY && bs_boxed->type == BS_ELEMENT_STRUCT) {
 	    bs_element_struct_t *bs_struct;
 	    long i, n;
@@ -827,7 +795,7 @@
     if (!ok)
     	rb_raise(rb_eArgError, "can't convert Ruby object `%s' to " \
 		 "Objective-C value of type `%s'", 
-		 RSTRING_PTR(rb_inspect(rval)), octype);
+		 RSTRING_CPTR(rb_inspect(rval)), octype);
 }
 
 VALUE
@@ -1744,7 +1712,7 @@
     }
 
     rb_bug("can't find field `%s' in recv `%s'", ivar_id_str,
-	   RSTRING_PTR(rb_inspect(recv)));
+	   RSTRING_CPTR(rb_inspect(recv)));
 }
 
 static VALUE
@@ -1831,12 +1799,12 @@
     d1 = bs_element_boxed_get_data(bs_boxed, recv, &ok);
     if (!ok)
 	rb_raise(rb_eRuntimeError, "can't retrieve data for boxed `%s'",
-		 RSTRING_PTR(rb_inspect(recv)));
+		 RSTRING_CPTR(rb_inspect(recv)));
 
     d2 = bs_element_boxed_get_data(bs_boxed, other, &ok);
     if (!ok)
 	rb_raise(rb_eRuntimeError, "can't retrieve data for boxed `%s'",
-		 RSTRING_PTR(rb_inspect(recv)));
+		 RSTRING_CPTR(rb_inspect(recv)));
 
     if (d1 == d2)
 	return Qtrue;
@@ -1856,7 +1824,7 @@
     data = bs_element_boxed_get_data(bs_boxed, recv, &ok);
     if (!ok)
 	rb_raise(rb_eRuntimeError, "can't retrieve data for boxed `%s'",
-		 RSTRING_PTR(rb_inspect(recv)));
+		 RSTRING_CPTR(rb_inspect(recv)));
 
     if (data == NULL)
 	return Qnil;
@@ -2262,7 +2230,7 @@
     rb_scan_args(argc, argv, "11", &framework, &search_network);
 
     Check_Type(framework, T_STRING);
-    cstr = RSTRING_PTR(framework);
+    cstr = RSTRING_CPTR(framework);
 
     fileManager = [NSFileManager defaultManager];
     path = [fileManager stringWithFileSystemRepresentation:cstr
@@ -2314,7 +2282,7 @@
 #undef FIND_LOAD_PATH_IN_LIBRARY
 
 	rb_raise(rb_eRuntimeError, "framework `%s' not found", 
-	    RSTRING_PTR(framework));
+	    RSTRING_CPTR(framework));
     }
 
 success:
@@ -2368,7 +2336,7 @@
     if (!ok)
 	[NSException raise:@"NSException" 
 	    format:@"can't get internal data for boxed type `%s'",
-	    RSTRING_PTR(rb_inspect((VALUE)rcv))];
+	    RSTRING_CPTR(rb_inspect((VALUE)rcv))];
     if (data == NULL) {
 	*(void **)buffer = NULL; 
     }

Modified: MacRuby/trunk/string.c
===================================================================
--- MacRuby/trunk/string.c	2008-05-28 20:03:03 UTC (rev 233)
+++ MacRuby/trunk/string.c	2008-05-28 23:51:40 UTC (rev 234)
@@ -4066,6 +4066,7 @@
     rb_backref_set(match);
 #if WITH_OBJC
     if (bang) {
+	rb_str_modify(str);
 	RSTRING_SYNC(str);
 	RSTRING_SYNC(dest);
 	CFStringReplaceAll((CFMutableStringRef)str, (CFStringRef)dest);

Modified: MacRuby/trunk/test/ruby/test_string.rb
===================================================================
--- MacRuby/trunk/test/ruby/test_string.rb	2008-05-28 20:03:03 UTC (rev 233)
+++ MacRuby/trunk/test/ruby/test_string.rb	2008-05-28 23:51:40 UTC (rev 234)
@@ -653,6 +653,9 @@
 
     a = S("hello")
     assert_nil(a.sub!(S('X'), S('Y')))
+
+    a = S("hello").freeze
+    assert_raise(RuntimeError) { a.gsub!(/./, '') }
   end
 
   def test_sub_hash

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/macruby-changes/attachments/20080528/88186d60/attachment.htm 


More information about the macruby-changes mailing list