summaryrefslogtreecommitdiff
path: root/marshal.c
diff options
context:
space:
mode:
authoryugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-10-25 14:45:47 +0000
committeryugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-10-25 14:45:47 +0000
commitd50e1bdcd766e8aa8b84133fe510e71a11ac6b10 (patch)
treebbd266343c5cc2c1ec4d1e26897f01a34db5f0bd /marshal.c
parent3354c14cd4515f87bbc4f4ba5cb9a4e2c361d678 (diff)
merges r24488, r24489 and r24493 from trunk into ruby_1_9_1.
-- * 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. -- * marshal.c (must_not_be_anonymous): fixed silly miss. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_1@25474 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'marshal.c')
-rw-r--r--marshal.c76
1 files changed, 42 insertions, 34 deletions
diff --git a/marshal.c b/marshal.c
index 8bbdd36982..aa0e7e8d04 100644
--- a/marshal.c
+++ b/marshal.c
@@ -168,19 +168,31 @@ mark_dump_arg(void *ptr)
rb_mark_hash(p->compat_tbl);
}
-static VALUE
-class2path(VALUE klass)
+static const char *
+must_not_be_anonymous(const char *type, VALUE path)
{
- VALUE path = rb_class_path(klass);
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(klass) == T_CLASS ? "class" : "module"),
- n);
+ rb_raise(rb_eTypeError, "can't dump anonymous %s %.*s", type,
+ (int)RSTRING_LEN(path), n);
}
- if (rb_path2class(n) != rb_class_real(klass)) {
- rb_raise(rb_eTypeError, "%s can't be referred", n);
+ return n;
+}
+
+static VALUE
+class2path(VALUE klass)
+{
+ VALUE path = rb_class_path(klass);
+ const char *n;
+
+ n = 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;
}
@@ -411,12 +423,10 @@ w_symbol(ID id, struct dump_arg *arg)
}
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);
@@ -432,8 +442,6 @@ hash_each(VALUE key, VALUE value, struct dump_call_arg *arg)
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)) {
@@ -442,7 +450,7 @@ w_extended(VALUE klass, struct dump_arg *arg, int check)
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);
@@ -452,8 +460,7 @@ w_extended(VALUE klass, struct dump_arg *arg, int check)
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;
@@ -463,8 +470,7 @@ w_class(char type, VALUE obj, struct dump_arg *arg, int check)
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);
}
@@ -477,7 +483,7 @@ w_uclass(VALUE obj, VALUE super, struct dump_arg *arg)
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);
}
}
@@ -952,7 +958,7 @@ mark_load_arg(void *ptr)
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)
@@ -1128,10 +1134,10 @@ r_symbol(struct load_arg *arg)
}
}
-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
@@ -1207,29 +1213,31 @@ r_ivar(VALUE obj, struct load_arg *arg)
}
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 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 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;
@@ -1598,7 +1606,7 @@ r_object0(struct load_arg *arg, int *ivp, VALUE extmod)
{
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);
}
@@ -1608,7 +1616,7 @@ r_object0(struct load_arg *arg, int *ivp, VALUE extmod)
{
volatile VALUE str = r_bytes(arg);
- v = path2class(RSTRING_PTR(str));
+ v = path2class(str);
v = r_entry(v, arg);
v = r_leave(v, arg);
}
@@ -1618,7 +1626,7 @@ r_object0(struct load_arg *arg, int *ivp, VALUE extmod)
{
volatile VALUE str = r_bytes(arg);
- v = path2module(RSTRING_PTR(str));
+ v = path2module(str);
v = r_entry(v, arg);
v = r_leave(v, arg);
}