[前][次][番号順一覧][スレッド一覧]

ruby-changes:2908

From: ko1@a...
Date: 21 Dec 2007 13:40:25 +0900
Subject: [ruby-changes:2908] nobu - Ruby:r14399 (trunk): * encoding.c (rb_enc_register): set encoding constant.

nobu	2007-12-21 13:40:13 +0900 (Fri, 21 Dec 2007)

  New Revision: 14399

  Modified files:
    trunk/ChangeLog
    trunk/encoding.c
    trunk/ruby.c

  Log:
    * encoding.c (rb_enc_register): set encoding constant.
    
    * encoding.c (rb_enc_find_index): replace non-alphanumeric chars with
      underscores, so that initialize function can be called.
    
    * ruby.c (proc_options, process_options): finds encoding after
      load_path is initialized.


  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ruby.c?r1=14399&r2=14398
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=14399&r2=14398
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/encoding.c?r1=14399&r2=14398

Index: encoding.c
===================================================================
--- encoding.c	(revision 14398)
+++ encoding.c	(revision 14399)
@@ -158,6 +158,7 @@
 }
 
 static VALUE enc_based_encoding(VALUE);
+static void set_encoding_const(const char *, rb_encoding *);
 int rb_enc_registered(const char *name);
 
 int
@@ -170,16 +171,21 @@
 	if (strcasecmp(name, rb_enc_name(oldenc))) {
 	    st_data_t key = (st_data_t)name, alias;
 	    st_delete(enc_table_alias, &key, &alias);
+	    index = enc_register(name, encoding);
 	}
 	else if (enc_initialized_p(oldenc) &&
-		 !NIL_P(enc_based_encoding(ENC_FROM_ENCODING(encoding)))) {
-	    return enc_register_at(index, name, encoding);
+		 !NIL_P(enc_based_encoding(ENC_FROM_ENCODING(oldenc)))) {
+	    enc_register_at(index, name, encoding);
 	}
 	else {
 	    rb_raise(rb_eArgError, "encoding %s is already registered", name);
 	}
     }
-    return enc_register(name, encoding);
+    else {
+	index = enc_register(name, encoding);
+    }
+    set_encoding_const(name, rb_enc_from_index(index));
+    return index;
 }
 
 int
@@ -293,6 +299,11 @@
     int i = rb_enc_registered(name);
     if (i < 0) {
 	VALUE enclib = rb_sprintf("enc/%s", name);
+	char *s = RSTRING_PTR(enclib) + 4, *e = RSTRING_END(enclib);
+	while (s < e) {
+	    if (!ISALNUM(*s)) *s = '_';
+	    ++s;
+	}
 	OBJ_FREEZE(enclib);
 	if (RTEST(rb_protect(require_enc, enclib, 0)))
 	    i = rb_enc_registered(name);
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 14398)
+++ ChangeLog	(revision 14399)
@@ -1,3 +1,13 @@
+Fri Dec 21 13:40:11 2007  Nobuyoshi Nakada  <nobu@r...>
+
+	* encoding.c (rb_enc_register): set encoding constant.
+
+	* encoding.c (rb_enc_find_index): replace non-alphanumeric chars with
+	  underscores, so that initialize function can be called.
+
+	* ruby.c (proc_options, process_options): finds encoding after
+	  load_path is initialized.
+
 Fri Dec 21 13:10:57 2007  Yukihiro Matsumoto  <matz@r...>
 
 	* io.c (rb_io_external_encoding): new method.
Index: ruby.c
===================================================================
--- ruby.c	(revision 14398)
+++ ruby.c	(revision 14399)
@@ -81,6 +81,7 @@
     int yydebug;
     char *script;
     VALUE e_script;
+    const char *enc_name;
     int enc_index;
 };
 
@@ -739,7 +740,7 @@
 		    break;
 		}
 		if (enc) {
-		    opt->enc_index = rb_enc_find_index(rb_enc_name(enc));
+		    opt->enc_name = rb_enc_name(enc);
 		}
 		s++;
 	    }
@@ -810,9 +811,7 @@
 		    rb_raise(rb_eRuntimeError, "missing argument for --encoding");
 		}
 	      encoding:
-		if ((opt->enc_index = rb_enc_find_index(s)) < 0) {
-		    rb_raise(rb_eRuntimeError, "unknown encoding name - %s", s);
-		}
+		opt->enc_name = s;
 	    }
 	    else if (strncmp("encoding=", s, 9) == 0) {
 		if (!*(s += 9)) goto noencoding;
@@ -981,6 +980,11 @@
     ruby_init_gems(opt);
     parser = rb_parser_new();
     if (opt->yydebug) rb_parser_set_yydebug(parser, Qtrue);
+    if ((s = opt->enc_name) != 0) {
+	if ((opt->enc_index = rb_enc_find_index(s)) < 0) {
+	    rb_raise(rb_eRuntimeError, "unknown encoding name - %s", s);
+	}
+    }
     if (opt->e_script) {
 	if (opt->enc_index >= 0)
 	    rb_enc_associate_index(opt->e_script, opt->enc_index);

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml

[前][次][番号順一覧][スレッド一覧]