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

source_changes at macosforge.org source_changes at macosforge.org
Tue Feb 16 20:09:23 PST 2010


Revision: 3565
          http://trac.macosforge.org/projects/ruby/changeset/3565
Author:   lsansonetti at apple.com
Date:     2010-02-16 20:09:22 -0800 (Tue, 16 Feb 2010)
Log Message:
-----------
more work

Modified Paths:
--------------
    MacRuby/branches/icu/encoding.c
    MacRuby/branches/icu/eval.c
    MacRuby/branches/icu/parse.y
    MacRuby/branches/icu/rakelib/builder/options.rb
    MacRuby/branches/icu/re.c
    MacRuby/branches/icu/string.c
    MacRuby/branches/icu/vm.cpp

Modified: MacRuby/branches/icu/encoding.c
===================================================================
--- MacRuby/branches/icu/encoding.c	2010-02-17 02:54:37 UTC (rev 3564)
+++ MacRuby/branches/icu/encoding.c	2010-02-17 04:09:22 UTC (rev 3565)
@@ -216,16 +216,12 @@
 	default:
 	    abort();
     }
-
-    // create constants
-    define_encoding_constant(public_name, encoding);
-    for (unsigned int i = 0; i < aliases_count; ++i) {
-	define_encoding_constant(aliases[i], encoding);
-    }
 }
 
-static void
-create_encodings(void)
+// This Init function is called very early. Do not use any runtime method
+// because things may not be initialized properly yet.
+void
+Init_PreEncoding(void)
 {
     add_encoding(ENCODING_BINARY,    ENCODING_TYPE_SPECIAL, "ASCII-8BIT",  1, true,  true,  "BINARY", NULL);
     add_encoding(ENCODING_ASCII,     ENCODING_TYPE_UCNV,    "US-ASCII",    1, true,  true,  "ASCII", "ANSI_X3.4-1968", "646", NULL);
@@ -251,7 +247,10 @@
 void
 Init_Encoding(void)
 {
-    rb_cEncoding = rb_define_class("Encoding", rb_cObject);
+    // rb_cEncoding is defined earlier in Init_PreVM().
+    rb_set_class_path(rb_cEncoding, rb_cObject, "Encoding");
+    rb_const_set(rb_cObject, rb_intern("Encoding"), rb_cEncoding);
+
     rb_undef_alloc_func(rb_cEncoding);
 
     rb_objc_define_method(rb_cEncoding, "to_s", mr_enc_name, 0);
@@ -283,7 +282,14 @@
     //rb_define_singleton_method(rb_cEncoding, "default_internal=", set_default_internal, 1);
     //rb_define_singleton_method(rb_cEncoding, "locale_charmap", rb_locale_charmap, 0);
 
-    create_encodings();
+    // Create constants.
+    for (unsigned int i = 0; i < ENCODINGS_COUNT; i++) {
+	rb_encoding_t *enc = rb_encodings[i];
+	define_encoding_constant(enc->public_name, enc);
+	for (unsigned int j = 0; j < enc->aliases_count; j++) {
+	    define_encoding_constant(enc->aliases[j], enc);
+	}
+    }
 }
 
 // MRI C-API compatibility.

Modified: MacRuby/branches/icu/eval.c
===================================================================
--- MacRuby/branches/icu/eval.c	2010-02-17 02:54:37 UTC (rev 3564)
+++ MacRuby/branches/icu/eval.c	2010-02-17 04:09:22 UTC (rev 3565)
@@ -39,6 +39,7 @@
 void Init_PreGC(void);
 void Init_PreVM(void);
 void Init_PreGCD(void);
+void Init_PreEncoding(void);
 
 bool ruby_dlog_enabled = false;
 FILE *ruby_dlog_file = NULL;
@@ -72,9 +73,10 @@
 	}
     }
 
-    Init_PreGC();
-    Init_PreVM();
-    Init_PreGCD();
+    Init_PreGC(); 	// requires nothing
+    Init_PreVM(); 	// requires nothing
+    Init_PreGCD(); 	// requires nothing
+    Init_PreEncoding(); // requires rb_cEncoding, GC
 
     rb_call_inits();
     ruby_prog_init();

Modified: MacRuby/branches/icu/parse.y
===================================================================
--- MacRuby/branches/icu/parse.y	2010-02-17 02:54:37 UTC (rev 3564)
+++ MacRuby/branches/icu/parse.y	2010-02-17 04:09:22 UTC (rev 3565)
@@ -9341,7 +9341,6 @@
     global_symbols.id_str = CFDictionaryCreateMutable(NULL,
 	0, NULL, NULL);
     GC_ROOT(&global_symbols.id_str);
-    rb_cSymbol = rb_objc_create_class("Symbol", (VALUE)objc_getClass("NSString"));
 #else
     global_symbols.sym_id = st_init_table_with_size(&symhash, 1000);
     global_symbols.id_str = st_init_numtable_with_size(1000);
@@ -9518,16 +9517,16 @@
 static inline VALUE
 rsymbol_new(const char *name, const int len, ID id)
 {
-    VALUE sym;
+    assert(rb_cSymbol != 0);
 
-    sym = (VALUE)orig_malloc(sizeof(struct RSymbol));
-    RSYMBOL(sym)->str = orig_malloc(len + 1);
-    RSYMBOL(sym)->klass = rb_cSymbol;
-    strcpy(RSYMBOL(sym)->str, name);
-    RSYMBOL(sym)->len = len;
-    RSYMBOL(sym)->id = id;
+    struct RSymbol *sym = (struct RSymbol *)orig_malloc(sizeof(struct RSymbol));
+    sym->klass = rb_cSymbol;
+    sym->str = orig_malloc(len + 1);
+    strcpy(sym->str, name);
+    sym->len = len;
+    sym->id = id;
     
-    return sym;
+    return (VALUE)sym;
 }
 #endif
 

Modified: MacRuby/branches/icu/rakelib/builder/options.rb
===================================================================
--- MacRuby/branches/icu/rakelib/builder/options.rb	2010-02-17 02:54:37 UTC (rev 3564)
+++ MacRuby/branches/icu/rakelib/builder/options.rb	2010-02-17 04:09:22 UTC (rev 3565)
@@ -99,8 +99,8 @@
 ARCHFLAGS = ARCHS.map { |a| '-arch ' + a }.join(' ')
 LLVM_MODULES = "core jit nativecodegen bitwriter"
 
-CC = '/usr/bin/gcc'
-CXX = '/usr/bin/g++'
+CC = '/usr/bin/gcc-4.2'
+CXX = '/usr/bin/g++-4.2'
 CFLAGS = "-I. -I./include -I./onig -I/usr/include/libxml2 #{ARCHFLAGS} -fno-common -pipe -O3 -g -Wall -fexceptions"
 CFLAGS << " -I./unicode" # TODO use /usr/local/include/unicode on FNI installs...
 CFLAGS << " -Wno-parentheses -Wno-deprecated-declarations -Werror" if NO_WARN_BUILD

Modified: MacRuby/branches/icu/re.c
===================================================================
--- MacRuby/branches/icu/re.c	2010-02-17 02:54:37 UTC (rev 3564)
+++ MacRuby/branches/icu/re.c	2010-02-17 04:09:22 UTC (rev 3565)
@@ -2452,7 +2452,7 @@
     buf = rb_str_buf_new(0);
 
     *fixed_enc = 0;
-    if (rb_enc_asciicompat(enc))
+    if (true) //rb_enc_asciicompat(enc))
         *fixed_enc = 0;
     else {
         *fixed_enc = enc;
@@ -3329,7 +3329,7 @@
 	    v = rb_check_regexp_type(e);
 	    if (!NIL_P(v)) {
                 rb_encoding *enc = rb_enc_get(v);
-                if (!rb_enc_asciicompat(enc)) {
+                if (false) {//!rb_enc_asciicompat(enc)) {
                     if (!has_ascii_incompat)
                         has_ascii_incompat = enc;
                     else if (has_ascii_incompat != enc)

Modified: MacRuby/branches/icu/string.c
===================================================================
--- MacRuby/branches/icu/string.c	2010-02-17 02:54:37 UTC (rev 3564)
+++ MacRuby/branches/icu/string.c	2010-02-17 04:09:22 UTC (rev 3565)
@@ -211,6 +211,8 @@
 	rb_encoding_t *enc)
 {
     assert(len >= 0);
+    assert(enc != NULL);
+
     self->flags = 0;
     self->encoding = enc;
     self->capacity_in_bytes = self->length_in_bytes = len;
@@ -1328,10 +1330,12 @@
     rb_cNSMutableString = (VALUE)objc_getClass("NSMutableString");
     assert(rb_cNSMutableString != 0);
 
-    rb_cRubyString = rb_define_class("String", rb_cNSMutableString);
+    // rb_cRubyString is defined earlier in Init_PreVM().
+    rb_set_class_path(rb_cRubyString, rb_cObject, "String");
+    rb_const_set(rb_cObject, rb_intern("String"), rb_cRubyString);
+
     rb_objc_define_method(*(VALUE *)rb_cRubyString, "alloc",
 	mr_str_s_alloc, 0);
-
     rb_objc_define_method(rb_cRubyString, "initialize", mr_str_initialize, -1);
     rb_objc_define_method(rb_cRubyString, "initialize_copy", mr_str_replace, 1);
     rb_objc_define_method(rb_cRubyString, "replace", mr_str_replace, 1);
@@ -1372,6 +1376,10 @@
     rb_fs = Qnil;
     rb_define_variable("$;", &rb_fs);
     rb_define_variable("$-F", &rb_fs);
+
+    // rb_cSymbol is defined earlier in Init_PreVM().
+    rb_set_class_path(rb_cSymbol, rb_cObject, "Symbol");
+    rb_const_set(rb_cObject, rb_intern("Symbol"), rb_cSymbol);
 }
 
 bool
@@ -1422,7 +1430,8 @@
 bstr_new_with_data(const uint8_t *bytes, long len)
 {
     rb_str_t *str = str_alloc(rb_cRubyString);
-    str_replace_with_bytes(str, (char *)bytes, len, ENCODING_BINARY);
+    str_replace_with_bytes(str, (char *)bytes, len,
+	    rb_encodings[ENCODING_BINARY]);
     return (VALUE)str;
 }
 
@@ -1469,7 +1478,7 @@
 VALUE
 rb_str_new(const char *cstr, long len)
 {
-    return rb_enc_str_new(cstr, len, ENCODING_BINARY);
+    return rb_enc_str_new(cstr, len, rb_encodings[ENCODING_BINARY]);
 }
 
 VALUE
@@ -1662,7 +1671,7 @@
 VALUE
 rb_str_buf_cat(VALUE str, const char *cstr, long len)
 {
-    return rb_enc_str_buf_cat(str, cstr, len, ENCODING_BINARY);
+    return rb_enc_str_buf_cat(str, cstr, len, rb_encodings[ENCODING_BINARY]);
 }
 
 VALUE
@@ -1751,6 +1760,9 @@
     if (IS_RSTR(str)) {
 	return (VALUE)str_dup(str);
     }
+    if (TYPE(str) == T_SYMBOL) {
+	return rb_str_new2(RSYMBOL(str)->str);
+    }
     abort(); // TODO
 }
 

Modified: MacRuby/branches/icu/vm.cpp
===================================================================
--- MacRuby/branches/icu/vm.cpp	2010-02-17 02:54:37 UTC (rev 3564)
+++ MacRuby/branches/icu/vm.cpp	2010-02-17 04:09:22 UTC (rev 3565)
@@ -4922,6 +4922,14 @@
     assert(m != NULL);
     old_resolveInstanceMethod_imp = method_getImplementation(m);
     method_setImplementation(m, (IMP)resolveInstanceMethod_imp);
+
+    // Early define some classes.
+    rb_cSymbol = rb_objc_create_class("Symbol",
+	    (VALUE)objc_getClass("NSString"));
+    rb_cEncoding = rb_objc_create_class("Encoding",
+	    (VALUE)objc_getClass("NSObject"));
+    rb_cRubyString = rb_objc_create_class("String",
+	    (VALUE)objc_getClass("NSMutableString"));
 }
 
 static VALUE
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20100216/fe7fe11c/attachment-0001.html>


More information about the macruby-changes mailing list