summaryrefslogtreecommitdiff
path: root/marshal.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-08-29 09:08:18 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-08-29 09:08:18 +0000
commit40bc4f5ae4ffe325c36a49e0d3280dbee2a39cee (patch)
tree834cc2146161802fb97d89f0a747ae794048169b /marshal.c
parent3bf972993f689965c857540ec1ccc729477e8e66 (diff)
* array.c (rb_ary_become): should not free ptr if it's shared.
* eval.c (rb_alias): prohibit making an alias named "allocate" if klass is a metaclass. * string.c (rb_string_value_ptr): StringValuePtr() should never return NULL pointer. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2764 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'marshal.c')
-rw-r--r--marshal.c25
1 files changed, 17 insertions, 8 deletions
diff --git a/marshal.c b/marshal.c
index 3b4761e..78d801b 100644
--- a/marshal.c
+++ b/marshal.c
@@ -466,11 +466,15 @@ w_object(obj, arg, limit)
case T_HASH:
w_uclass(obj, rb_cHash, arg);
- if (!NIL_P(RHASH(obj)->ifnone)) {
- w_byte(TYPE_HASH_DEF, arg);
+ if (NIL_P(RHASH(obj)->ifnone)) {
+ w_byte(TYPE_HASH, arg);
+ }
+ else if (FL_TEST(obj, FL_USER2)) {
+ /* FL_USER2 means HASH_PROC_DEFAULT (see hash.c) */
+ rb_raise(rb_eArgError, "cannot dump hash with default proc");
}
else {
- w_byte(TYPE_HASH, arg);
+ w_byte(TYPE_HASH_DEF, arg);
}
w_long(RHASH(obj)->tbl->num_entries, arg);
st_foreach(RHASH(obj)->tbl, hash_each, &c_arg);
@@ -1047,12 +1051,17 @@ r_object0(arg, proc)
VALUE klass;
klass = rb_path2class(r_unique(arg));
- if (!rb_respond_to(klass, s_alloc)) {
- rb_raise(rb_eTypeError,
- "class %s needs to have class method `_alloc'",
- rb_class2name(klass));
+ if (rb_respond_to(klass, s_alloc)) {
+ static int warn = Qtrue;
+ if (warn) {
+ rb_warn("define `allocate' instead of `_alloc'");
+ warn = Qfalse;
+ }
+ v = rb_funcall(klass, s_alloc, 0);
}
- v = rb_funcall(klass, s_alloc, 0);
+ else {
+ v = rb_obj_alloc(klass);
+ }
if (TYPE(v) != T_DATA) {
rb_raise(rb_eArgError, "dump format error");
}