[macruby-changes] [3549] MacRuby/branches/icu

source_changes at macosforge.org source_changes at macosforge.org
Mon Feb 15 19:32:10 PST 2010


Revision: 3549
          http://trac.macosforge.org/projects/ruby/changeset/3549
Author:   lsansonetti at apple.com
Date:     2010-02-15 19:32:07 -0800 (Mon, 15 Feb 2010)
Log Message:
-----------
remove references of rb_cByteString (except in io.c), more work on MRI functions

Modified Paths:
--------------
    MacRuby/branches/icu/file.c
    MacRuby/branches/icu/include/ruby/ruby.h
    MacRuby/branches/icu/io.c
    MacRuby/branches/icu/marshal.c
    MacRuby/branches/icu/parse.y
    MacRuby/branches/icu/re.c
    MacRuby/branches/icu/ruby.c
    MacRuby/branches/icu/string.c
    MacRuby/branches/icu/time.c

Modified: MacRuby/branches/icu/file.c
===================================================================
--- MacRuby/branches/icu/file.c	2010-02-16 03:04:03 UTC (rev 3548)
+++ MacRuby/branches/icu/file.c	2010-02-16 03:32:07 UTC (rev 3549)
@@ -113,26 +113,11 @@
 	tmp = obj;
     }
   exit:
-    if (CLASS_OF(tmp) == rb_cByteString) {
-	const long len = rb_bytestring_length(tmp);
-	char *buf = (char *)alloca(len + 1);
-	memcpy(buf, (const char *)rb_bytestring_byte_pointer(tmp), len); 
-	buf[len] = '\0';
-	CFStringRef str = CFStringCreateWithFileSystemRepresentation(NULL,
-		buf);
-	if (str == NULL) {
-	    rb_raise(rb_eRuntimeError,
-		    "can't convert given ByteString to path");
-	}
-	return (VALUE)CFMakeCollectable(str);
+    StringValueCStr(tmp);
+    if (check && obj != tmp) {
+	rb_check_safe_obj(tmp);
     }
-    else {
-	StringValueCStr(tmp);
-	if (check && obj != tmp) {
-	    rb_check_safe_obj(tmp);
-	}
-	return rb_str_new4(tmp);
-    }
+    return rb_str_new4(tmp);
 }
 
 VALUE
@@ -2600,9 +2585,6 @@
 	    VALUE tmp = RARRAY_AT(ary, i);
 	    switch (TYPE(tmp)) {
 		case T_STRING:
-		    if (*(VALUE *)tmp == rb_cByteString) {
-			tmp = (VALUE)rb_bytestring_resolve_cfstring(tmp);
-		    }
 		    break;
 
 		case T_ARRAY:

Modified: MacRuby/branches/icu/include/ruby/ruby.h
===================================================================
--- MacRuby/branches/icu/include/ruby/ruby.h	2010-02-16 03:04:03 UTC (rev 3548)
+++ MacRuby/branches/icu/include/ruby/ruby.h	2010-02-16 03:32:07 UTC (rev 3549)
@@ -1120,7 +1120,6 @@
 RUBY_EXTERN VALUE rb_cSet;
 RUBY_EXTERN VALUE rb_cStat;
 RUBY_EXTERN VALUE rb_cString;
-RUBY_EXTERN VALUE rb_cByteString;
 RUBY_EXTERN VALUE rb_cStruct;
 RUBY_EXTERN VALUE rb_cSymbol;
 RUBY_EXTERN VALUE rb_cThread;
@@ -1408,20 +1407,20 @@
 /* locale insensitive functions */
 
 #define rb_isascii(c) ((unsigned long)(c) < 128)
-int rb_isalnum(int c);
-int rb_isalpha(int c);
-int rb_isblank(int c);
-int rb_iscntrl(int c);
-int rb_isdigit(int c);
-int rb_isgraph(int c);
-int rb_islower(int c);
-int rb_isprint(int c);
-int rb_ispunct(int c);
-int rb_isspace(int c);
-int rb_isupper(int c);
-int rb_isxdigit(int c);
-int rb_tolower(int c);
-int rb_toupper(int c);
+#define rb_isalnum(c) (rb_isascii(c) && isalnum(c))
+#define rb_isalpha(c) (rb_isascii(c) && isalpha(c))
+#define rb_isblank(c) (rb_isascii(c) && isblank(c))
+#define rb_iscntrl(c) (rb_isascii(c) && iscntrl(c))
+#define rb_isdigit(c) (rb_isascii(c) && isdigit(c))
+#define rb_isgraph(c) (rb_isascii(c) && isgraph(c))
+#define rb_islower(c) (rb_isascii(c) && islower(c))
+#define rb_isprint(c) (rb_isascii(c) && isprint(c))
+#define rb_ispunct(c) (rb_isascii(c) && ispunct(c))
+#define rb_isspace(c) (rb_isascii(c) && isspace(c))
+#define rb_isupper(c) (rb_isascii(c) && isupper(c))
+#define rb_isxdigit(c) (rb_isascii(c) && isxdigit(c))
+#define rb_tolower(c) (rb_isascii(c) && tolower(c))
+#define rb_toupper(c) (rb_isascii(c) && toupper(c))
 
 #ifndef ISPRINT
 #define ISASCII(c) rb_isascii((unsigned char)(c))

Modified: MacRuby/branches/icu/io.c
===================================================================
--- MacRuby/branches/icu/io.c	2010-02-16 03:04:03 UTC (rev 3548)
+++ MacRuby/branches/icu/io.c	2010-02-16 03:32:07 UTC (rev 3549)
@@ -17,6 +17,8 @@
 #include "objc.h"
 #include "id.h"
 
+extern VALUE rb_cByteString; // TODO it does not exist anymore
+
 #include <errno.h>
 #include <paths.h>
 #include <fcntl.h>

Modified: MacRuby/branches/icu/marshal.c
===================================================================
--- MacRuby/branches/icu/marshal.c	2010-02-16 03:04:03 UTC (rev 3548)
+++ MacRuby/branches/icu/marshal.c	2010-02-16 03:32:07 UTC (rev 3549)
@@ -1733,17 +1733,6 @@
     v = rb_check_string_type(port);
     if (!NIL_P(v)) {
 	arg->taint = OBJ_TAINTED(port); /* original taintedness */
-	if (*(VALUE *)v != rb_cByteString) {
-	    // Given string is not a ByteString, let's create one based on every
-	    // character. This sucks but this is how life is.
-	    const long n = RSTRING_LEN(v);
-	    UInt8 *bytes = alloca(n + 1);
-	    for (long i = 0; i < n; i++) {
-		UniChar c = CFStringGetCharacterAtIndex((CFStringRef)v, i);
-		bytes[i] = (char)c;
-	    }
-	    v = rb_bytestring_new_with_data(bytes, n);
-	}
 	port = v;
     }
     else if (rb_obj_respond_to(port, s_getbyte, Qtrue)

Modified: MacRuby/branches/icu/parse.y
===================================================================
--- MacRuby/branches/icu/parse.y	2010-02-16 03:04:03 UTC (rev 3548)
+++ MacRuby/branches/icu/parse.y	2010-02-16 03:32:07 UTC (rev 3549)
@@ -5066,33 +5066,7 @@
 }
 #endif /* !RIPPER */
 
-#ifndef RIPPER
 static VALUE
-lex_get_bstr(struct parser_params *parser, VALUE s)
-{
-    long beg = 0; 
-    const long n = rb_bytestring_length(s);
-    if (lex_gets_ptr > 0) {
-	if (n == lex_gets_ptr) {
-	    return Qnil;
-	}
-	beg += lex_gets_ptr;
-    }
-
-    const UInt8 *data = rb_bytestring_byte_pointer(s);
-    UInt8 *pos = memchr(data + beg, '\n', n - beg);
-    if (pos != NULL) {
-	lex_gets_ptr = pos - data + 1;
-    }
-    else {
-	lex_gets_ptr = n;
-    }
-
-    return rb_bytestring_new_with_data(data + beg, lex_gets_ptr - beg);
-}
-#endif
-
-static VALUE
 lex_get_str(struct parser_params *parser, VALUE s)
 {
     long beg = 0, len; 
@@ -5149,7 +5123,7 @@
     struct parser_params *parser;
     Data_Get_Struct(vparser, struct parser_params, parser);
 
-    lex_gets = CLASS_OF(s) == rb_cByteString ? lex_get_bstr : lex_get_str;
+    lex_gets = lex_get_str;
     lex_gets_ptr = 0;
     GC_WB(&lex_input, s);
     lex_pbeg = lex_p = lex_pend = 0;

Modified: MacRuby/branches/icu/re.c
===================================================================
--- MacRuby/branches/icu/re.c	2010-02-16 03:04:03 UTC (rev 3548)
+++ MacRuby/branches/icu/re.c	2010-02-16 03:32:07 UTC (rev 3549)
@@ -1303,12 +1303,6 @@
 rb_reg_prepare_enc(VALUE re, VALUE str, char **pcstr, size_t *pcharsize,
 	bool *should_free)
 {
-    if (*(VALUE *)str == rb_cByteString) {
-	*pcstr = (char *)rb_bytestring_byte_pointer(str);
-	*pcharsize = 1;
-	*should_free = false;
-	return (rb_encoding *)ONIG_ENCODING_ASCII;
-    }
     CFStringEncoding enc = CFStringGetSmallestEncoding((CFStringRef)str);
     switch (enc) {
 	default:

Modified: MacRuby/branches/icu/ruby.c
===================================================================
--- MacRuby/branches/icu/ruby.c	2010-02-16 03:04:03 UTC (rev 3548)
+++ MacRuby/branches/icu/ruby.c	2010-02-16 03:32:07 UTC (rev 3549)
@@ -1093,8 +1093,6 @@
 		if (NIL_P(line)) {
 		    return 0;
 		}
-		assert(*(VALUE *)line == rb_cByteString);
-
 		if ((p = strstr(RSTRING_PTR(line), "ruby")) == 0) {
 		    /* not ruby script, kick the program */
 		    char **argv;

Modified: MacRuby/branches/icu/string.c
===================================================================
--- MacRuby/branches/icu/string.c	2010-02-16 03:04:03 UTC (rev 3548)
+++ MacRuby/branches/icu/string.c	2010-02-16 03:32:07 UTC (rev 3549)
@@ -9,14 +9,16 @@
  * Copyright (C) 2000 Information-technology Promotion Agency, Japan
  */
 
-#include "encoding.h"
-#include "objc.h"
-#include <assert.h>
 #include <stdio.h>
 #include <stdarg.h>
 
-VALUE rb_cSymbol; // XXX move me outside
+#include "encoding.h"
+#include "objc.h"
+#include "id.h"
 
+VALUE rb_cSymbol; 	// XXX move me outside
+VALUE rb_cByteString; 	// XXX remove all references about me, i'm dead
+
 VALUE rb_cString;
 VALUE rb_cNSString;
 VALUE rb_cNSMutableString;
@@ -1406,6 +1408,21 @@
     return rb_tainted_str_new(cstr, strlen(cstr));
 }
 
+VALUE
+rb_usascii_str_new(const char *cstr, long len)
+{
+    VALUE str = rb_str_new(cstr, len);
+    RSTR(str)->encoding = encodings[ENCODING_ASCII];
+    return str;
+}
+
+VALUE
+rb_usascii_str_new2(const char *cstr)
+{
+    return rb_usascii_str_new(cstr, strlen(cstr));
+}
+
+
 const char *
 rb_str_cstr(VALUE str)
 {
@@ -1426,6 +1443,52 @@
     return 0; // TODO
 }
 
+char *
+rb_string_value_cstr(volatile VALUE *ptr)
+{
+    VALUE str = rb_string_value(ptr);
+    return (char *)rb_str_cstr(str);
+}
+
+char *
+rb_string_value_ptr(volatile VALUE *ptr)
+{
+    return rb_string_value_cstr(ptr);
+}
+
+VALUE
+rb_string_value(volatile VALUE *ptr)
+{
+    VALUE s = *ptr;
+    if (TYPE(s) != T_STRING) {
+	s = rb_str_to_str(s);
+	*ptr = s;
+    }
+    return s;
+}
+
+VALUE
+rb_check_string_type(VALUE str)
+{
+    return rb_check_convert_type(str, T_STRING, "String", "to_str");
+}
+
+VALUE
+rb_obj_as_string(VALUE obj)
+{
+    if (TYPE(obj) == T_STRING || TYPE(obj) == T_SYMBOL) {
+	return obj;
+    }
+    VALUE str = rb_vm_call(obj, selToS, 0, NULL, false);
+    if (TYPE(str) != T_STRING) {
+	return rb_any_to_s(obj);
+    }
+    if (OBJ_TAINTED(obj)) {
+	OBJ_TAINT(str);
+    }
+    return str;
+}
+
 ID
 rb_to_id(VALUE name)
 {

Modified: MacRuby/branches/icu/time.c
===================================================================
--- MacRuby/branches/icu/time.c	2010-02-16 03:04:03 UTC (rev 3548)
+++ MacRuby/branches/icu/time.c	2010-02-16 03:32:07 UTC (rev 3549)
@@ -2238,7 +2238,6 @@
     rb_copy_generic_ivar(time, str);
 
     StringValue(str);
-    assert(*(VALUE *)str == rb_cByteString);
 
     unsigned char *buf = (unsigned char *)rb_bytestring_byte_pointer(str);
     const size_t buflen = rb_bytestring_length(str); 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20100215/bdeb8beb/attachment-0001.html>


More information about the macruby-changes mailing list