summaryrefslogtreecommitdiff
path: root/marshal.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-04-24 04:54:16 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-04-24 04:54:16 +0000
commite3a8c626308cb8546baaf75e6133df304142f0c8 (patch)
tree4fb40e7eab065c70d5b2cdb44eb16bea01b12c15 /marshal.c
parentb596fbbc375ea58aa2b869cb6025b2bb101f96b9 (diff)
* io.c (rb_io_mode_flags): both 'r+b' and 'rb+' should be allowed.
* io.c (rb_io_mode_modenum): ditto. * gc.c (rb_memerror): rename from mem_error, and exported. * gc.c (Init_GC): pre-allocate NoMemoryError instance. * object.c (convert_type): error message changed from "failed to convert" to "cannot convert", since it does not try to convert if an object does not respond to the converting method. * eval.c (block_pass): convert Method to Proc using rb_check_convert_type(). * object.c (rb_check_convert_type): always convert T_DATA * eval.c (rb_thread_cleanup): should not terminate main_thread by Fatal error. * regex.c (is_in_list): need to not exclude NUL and NEWLINE. * re.c (rb_reg_expr_str): wrong backslash escapement. * re.c (rb_reg_expr_str): do not escape embedded space characters. * marshal.c (w_object): T_DATA process patch from Joel VanderWerf <vjoel@PATH.Berkeley.EDU>. This is temporary hack; it remains undocumented, and it will be removed when marshaling is re-designed. * marshal.c (r_object): ditto. * numeric.c (num_step): Integer#step is moved to Numeric#step; Fixnum#step is merged into this method. * numeric.c (int_dotimes): Fixnum#times is merged. * numeric.c (int_upto): Fixnum#upto is merged. * numeric.c (int_downto): Fixnum#downto is merged. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2401 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'marshal.c')
-rw-r--r--marshal.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/marshal.c b/marshal.c
index b15af3b620..738f7edd62 100644
--- a/marshal.c
+++ b/marshal.c
@@ -55,6 +55,7 @@ shortlen(len, ds)
#define TYPE_UCLASS 'C'
#define TYPE_OBJECT 'o'
+#define TYPE_DATA 'd'
#define TYPE_USERDEF 'u'
#define TYPE_USRMARHAL 'U'
#define TYPE_FLOAT 'f'
@@ -76,6 +77,7 @@ shortlen(len, ds)
#define TYPE_LINK '@'
static ID s_dump, s_load;
+static ID s_dump_data, s_load_data, s_alloc;
struct dump_arg {
VALUE obj;
@@ -490,6 +492,34 @@ w_object(obj, arg, limit)
}
break;
+ case T_DATA:
+ w_byte(TYPE_DATA, arg);
+ {
+ VALUE klass = CLASS_OF(obj);
+ char *path;
+
+ if (FL_TEST(klass, FL_SINGLETON)) {
+ if (RCLASS(klass)->m_tbl->num_entries > 0 ||
+ RCLASS(klass)->iv_tbl->num_entries > 1) {
+ rb_raise(rb_eTypeError, "singleton can't be dumped");
+ }
+ }
+ path = rb_class2name(klass);
+ w_unique(path, arg);
+ }
+ {
+ VALUE v;
+
+ if (!rb_respond_to(obj, s_dump_data)) {
+ rb_raise(rb_eTypeError,
+ "class %s needs to have instance method `_dump_data'",
+ rb_class2name(CLASS_OF(obj)));
+ }
+ v = rb_funcall(obj, s_dump_data, 0);
+ w_object(v, arg, limit);
+ }
+ break;
+
default:
rb_raise(rb_eTypeError, "can't dump %s",
rb_class2name(CLASS_OF(obj)));
@@ -1010,6 +1040,30 @@ r_object(arg)
}
break;
+ case TYPE_DATA:
+ {
+ 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));
+ }
+ v = rb_funcall(klass, s_alloc, 0);
+ if (TYPE(v) != T_DATA) {
+ rb_raise(rb_eArgError, "dump format error");
+ }
+ r_regist(v, arg);
+ if (!rb_respond_to(v, s_load_data)) {
+ rb_raise(rb_eTypeError,
+ "class %s needs to have instance method `_load_data'",
+ rb_class2name(klass));
+ }
+ rb_funcall(v, s_load_data, 1, r_object(arg));
+ }
+ break;
+
case TYPE_MODULE_OLD:
{
char *buf;
@@ -1134,6 +1188,9 @@ Init_marshal()
s_dump = rb_intern("_dump");
s_load = rb_intern("_load");
+ s_dump_data = rb_intern("_dump_data");
+ s_load_data = rb_intern("_load_data");
+ s_alloc = rb_intern("_alloc");
rb_define_module_function(rb_mMarshal, "dump", marshal_dump, -1);
rb_define_module_function(rb_mMarshal, "load", marshal_load, -1);
rb_define_module_function(rb_mMarshal, "restore", marshal_load, -1);