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

ruby-changes:12763

From: nobu <ko1@a...>
Date: Mon, 10 Aug 2009 06:56:21 +0900 (JST)
Subject: [ruby-changes:12763] Ruby:r24488 (trunk): * marshal.c (class2path, w_unique, w_extended, w_class, w_uclass):

nobu	2009-08-10 06:55:55 +0900 (Mon, 10 Aug 2009)

  New Revision: 24488

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=24488

  Log:
    * marshal.c (class2path, w_unique, w_extended, w_class, w_uclass):
      deal with non-ascii class path.  [ruby-core:24790]
    * marshal.c (r_unique, path2class, path2module, obj_alloc_by_path),
      (r_object0): ditto.
    
    * variable.c (rb_path_to_class): new encoding-aware function to
      get a class from its name.

  Modified files:
    trunk/ChangeLog
    trunk/common.mk
    trunk/include/ruby/intern.h
    trunk/marshal.c
    trunk/variable.c
    trunk/version.h

Index: include/ruby/intern.h
===================================================================
--- include/ruby/intern.h	(revision 24487)
+++ include/ruby/intern.h	(revision 24488)
@@ -760,7 +760,8 @@
 VALUE rb_class_path(VALUE);
 void rb_set_class_path(VALUE, VALUE, const char*);
 void rb_set_class_path_string(VALUE, VALUE, VALUE);
-VALUE rb_path2class(const char*);
+VALUE rb_path_to_class(VALUE);
+DEPRECATED(VALUE rb_path2class(const char*));
 void rb_name_class(VALUE, ID);
 VALUE rb_class_name(VALUE);
 void rb_autoload(VALUE, ID, const char*);
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 24487)
+++ ChangeLog	(revision 24488)
@@ -1,3 +1,14 @@
+Mon Aug 10 06:55:45 2009  Nobuyoshi Nakada  <nobu@r...>
+
+	* marshal.c (class2path, w_unique, w_extended, w_class, w_uclass):
+	  deal with non-ascii class path.  [ruby-core:24790]
+
+	* marshal.c (r_unique, path2class, path2module, obj_alloc_by_path),
+	  (r_object0): ditto.
+
+	* variable.c (rb_path_to_class): new encoding-aware function to
+	  get a class from its name.
+
 Sun Aug  9 21:14:03 2009  Hidetoshi NAGAI  <nagai@a...>
 
 	* ext/tk/extconf.rb (search_tclConfig): last change isn't enough.
Index: variable.c
===================================================================
--- variable.c	(revision 24487)
+++ variable.c	(revision 24488)
@@ -14,6 +14,7 @@
 #include "ruby/ruby.h"
 #include "ruby/st.h"
 #include "ruby/util.h"
+#include "ruby/encoding.h"
 #include "node.h"
 
 void rb_vm_change_state(void);
@@ -249,19 +250,23 @@
 }
 
 VALUE
-rb_path2class(const char *path)
+rb_path_to_class(VALUE pathname)
 {
-    const char *pbeg, *p;
+    rb_encoding *enc = rb_enc_get(pathname);
+    const char *pbeg, *p, *path = RSTRING_PTR(pathname);
     ID id;
     VALUE c = rb_cObject;
 
+    if (!rb_enc_asciicompat(enc)) {
+	rb_raise(rb_eArgError, "invalid class path encoding (non ASCII)");
+    }
+    pbeg = p = path;
     if (path[0] == '#') {
 	rb_raise(rb_eArgError, "can't retrieve anonymous class %s", path);
     }
-    pbeg = p = path;
     while (*p) {
 	while (*p && *p != ':') p++;
-	id = rb_intern2(pbeg, p-pbeg);
+	id = rb_intern3(pbeg, p-pbeg, enc);
 	if (p[0] == ':') {
 	    if (p[1] != ':') goto undefined_class;
 	    p += 2;
@@ -284,6 +289,12 @@
     return c;
 }
 
+VALUE
+rb_path2class(const char *path)
+{
+    return rb_path_to_class(rb_usascii_str_new_cstr(path));
+}
+
 void
 rb_name_class(VALUE klass, ID id)
 {
Index: common.mk
===================================================================
--- common.mk	(revision 24487)
+++ common.mk	(revision 24488)
@@ -602,7 +602,7 @@
   $(ENCODING_H_INCLUDES)
 util.$(OBJEXT): {$(VPATH)}util.c $(RUBY_H_INCLUDES) {$(VPATH)}util.h
 variable.$(OBJEXT): {$(VPATH)}variable.c $(RUBY_H_INCLUDES) \
-  {$(VPATH)}node.h {$(VPATH)}util.h
+  {$(VPATH)}node.h {$(VPATH)}util.h {$(VPATH)}encoding.h
 version.$(OBJEXT): {$(VPATH)}version.c $(RUBY_H_INCLUDES) \
   {$(VPATH)}version.h $(srcdir)/revision.h
 
Index: version.h
===================================================================
--- version.h	(revision 24487)
+++ version.h	(revision 24488)
@@ -1,5 +1,5 @@
 #define RUBY_VERSION "1.9.2"
-#define RUBY_RELEASE_DATE "2009-08-09"
+#define RUBY_RELEASE_DATE "2009-08-10"
 #define RUBY_PATCHLEVEL -1
 #define RUBY_BRANCH_NAME "trunk"
 
@@ -8,7 +8,7 @@
 #define RUBY_VERSION_TEENY 1
 #define RUBY_RELEASE_YEAR 2009
 #define RUBY_RELEASE_MONTH 8
-#define RUBY_RELEASE_DAY 9
+#define RUBY_RELEASE_DAY 10
 
 #include "ruby/version.h"
 
Index: marshal.c
===================================================================
--- marshal.c	(revision 24487)
+++ marshal.c	(revision 24488)
@@ -168,18 +168,28 @@
     rb_mark_hash(p->compat_tbl);
 }
 
+static void
+must_not_be_anonymous(const char *type, VALUE path)
+{
+    char *n = RSTRING_PTR(path);
+
+    if (!rb_enc_asciicompat(rb_enc_get(path))) {
+	/* cannot occur? */
+	rb_raise(rb_eTypeError, "can't dump non-ascii %s name", type);
+    }
+    if (n[0] == '#') {
+	rb_raise(rb_eTypeError, "can't dump anonymous %s %s", type,
+		 (int)RSTRING_LEN(path), n);
+    }
+}
+
 static VALUE
 class2path(VALUE klass)
 {
     VALUE path = rb_class_path(klass);
-    char *n = RSTRING_PTR(path);
 
-    if (n[0] == '#') {
-	rb_raise(rb_eTypeError, "can't dump anonymous %s %s",
-		 (TYPE(klass) == T_CLASS ? "class" : "module"),
-		 n);
-    }
-    if (rb_path2class(n) != rb_class_real(klass)) {
+    must_not_be_anonymous((TYPE(klass) == T_CLASS ? "class" : "module"), path);
+    if (rb_path_to_class(path) != rb_class_real(klass)) {
 	rb_raise(rb_eTypeError, "%s can't be referred to", n);
     }
     return path;
@@ -412,12 +422,10 @@
 }
 
 static void
-w_unique(const char *s, struct dump_arg *arg)
+w_unique(VALUE s, struct dump_arg *arg)
 {
-    if (s[0] == '#') {
-	rb_raise(rb_eTypeError, "can't dump anonymous class %s", s);
-    }
-    w_symbol(rb_intern(s), arg);
+    must_not_be_anonymous("class", s);
+    w_symbol(rb_intern_str(s), arg);
 }
 
 static void w_object(VALUE,struct dump_arg*,int);
@@ -433,8 +441,6 @@
 static void
 w_extended(VALUE klass, struct dump_arg *arg, int check)
 {
-    const char *path;
-
     if (check && FL_TEST(klass, FL_SINGLETON)) {
 	if (RCLASS_M_TBL(klass)->num_entries ||
 	    (RCLASS_IV_TBL(klass) && RCLASS_IV_TBL(klass)->num_entries > 1)) {
@@ -443,7 +449,7 @@
 	klass = RCLASS_SUPER(klass);
     }
     while (BUILTIN_TYPE(klass) == T_ICLASS) {
-	path = rb_class2name(RBASIC(klass)->klass);
+	VALUE path = rb_class_name(RBASIC(klass)->klass);
 	w_byte(TYPE_EXTENDED, arg);
 	w_unique(path, arg);
 	klass = RCLASS_SUPER(klass);
@@ -453,8 +459,7 @@
 static void
 w_class(char type, VALUE obj, struct dump_arg *arg, int check)
 {
-    volatile VALUE p;
-    char *path;
+    VALUE path;
     st_data_t real_obj;
     VALUE klass;
 
@@ -464,8 +469,7 @@
     klass = CLASS_OF(obj);
     w_extended(klass, arg, check);
     w_byte(type, arg);
-    p = class2path(rb_class_real(klass));
-    path = RSTRING_PTR(p);
+    path = class2path(rb_class_real(klass));
     w_unique(path, arg);
 }
 
@@ -478,7 +482,7 @@
     klass = rb_class_real(klass);
     if (klass != super) {
 	w_byte(TYPE_UCLASS, arg);
-	w_unique(RSTRING_PTR(class2path(klass)), arg);
+	w_unique(class2path(klass), arg);
     }
 }
 
@@ -967,7 +971,7 @@
 static VALUE r_entry(VALUE v, struct load_arg *arg);
 static VALUE r_object(struct load_arg *arg);
 static ID r_symbol(struct load_arg *arg);
-static VALUE path2class(const char *path);
+static VALUE path2class(VALUE path);
 
 static int
 r_byte(struct load_arg *arg)
@@ -1143,10 +1147,10 @@
     }
 }
 
-static const char*
+static VALUE
 r_unique(struct load_arg *arg)
 {
-    return rb_id2name(r_symbol(arg));
+    return rb_id2str(r_symbol(arg));
 }
 
 static VALUE
@@ -1222,29 +1226,31 @@
 }
 
 static VALUE
-path2class(const char *path)
+path2class(VALUE path)
 {
-    VALUE v = rb_path2class(path);
+    VALUE v = rb_path_to_class(path);
 
     if (TYPE(v) != T_CLASS) {
-	rb_raise(rb_eArgError, "%s does not refer to class", path);
+	rb_raise(rb_eArgError, "%.*s does not refer to class",
+		 (int)RSTRING_LEN(path), RSTRING_PTR(path));
     }
     return v;
 }
 
 static VALUE
-path2module(const char *path)
+path2module(VALUE path)
 {
-    VALUE v = rb_path2class(path);
+    VALUE v = rb_path_to_class(path);
 
     if (TYPE(v) != T_MODULE) {
-	rb_raise(rb_eArgError, "%s does not refer to module", path);
+	rb_raise(rb_eArgError, "%.*s does not refer to module",
+		 (int)RSTRING_LEN(path), RSTRING_PTR(path));
     }
     return v;
 }
 
 static VALUE
-obj_alloc_by_path(const char *path, struct load_arg *arg)
+obj_alloc_by_path(VALUE path, struct load_arg *arg)
 {
     VALUE klass;
     st_data_t data;
@@ -1615,7 +1621,7 @@
         {
 	    volatile VALUE str = r_bytes(arg);
 
-	    v = rb_path2class(RSTRING_PTR(str));
+	    v = rb_path_to_class(str);
 	    v = r_entry(v, arg);
             v = r_leave(v, arg);
 	}
@@ -1625,7 +1631,7 @@
         {
 	    volatile VALUE str = r_bytes(arg);
 
-	    v = path2class(RSTRING_PTR(str));
+	    v = path2class(str);
 	    v = r_entry(v, arg);
             v = r_leave(v, arg);
 	}
@@ -1635,7 +1641,7 @@
         {
 	    volatile VALUE str = r_bytes(arg);
 
-	    v = path2module(RSTRING_PTR(str));
+	    v = path2module(str);
 	    v = r_entry(v, arg);
             v = r_leave(v, arg);
 	}

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

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