Hi,

Fowarding.


Delivery-Date: Thu Jan 16 06:05:13 2003 Date: Wed, 15 Jan 2003 12:54:51 -0800 From: Ryan Pavlik <rpav / nwlink.com> Subject: Marshal patch Hi, I apologize if I'm sending this to the wrong place---but here's a simple patch for marshal.c that adds _pre_dump and _post_load calls. Would it be possible to get this integrated into 1.8? The usefulness is as follows: if you merely need to alter an object before serialization, but the default marshal routine is OK, then this lets you do that. For instance, I can walk through an object and replace any Persistant objects with an OID for the object (in the database), then restore the references from the database on load. If I should send this to someone else, please let me know. Thanks. -- Ryan Pavlik <rpav / users.sf.net> "Now if you'll excuse me, I've got to single-handedly save a film genre."
diff -ru ruby-1.8.0/marshal.c ruby-1.8.0-rpav/marshal.c --- ruby-1.8.0/marshal.c 2002-12-23 15:55:30.000000000 -0800 +++ ruby-1.8.0-rpav/marshal.c 2003-01-15 12:14:13.000000000 -0800 @@ -77,6 +77,7 @@ static ID s_dump, s_load; static ID s_dump_data, s_load_data, s_alloc; static ID s_getc, s_read, s_write; +static ID s_pre_dump, s_post_load; struct dump_arg { VALUE obj; @@ -343,6 +344,10 @@ if (limit == 0) { rb_raise(rb_eArgError, "exceed depth limit"); } + + if(rb_respond_to(obj, s_pre_dump)) + rb_funcall(obj, s_pre_dump, 1, INT2NUM(limit)); + if (obj == Qnil) { w_byte(TYPE_NIL, arg); } @@ -1183,7 +1188,12 @@ r_object(arg) struct load_arg *arg; { - return r_object0(arg, arg->proc); + VALUE v = r_object0(arg, arg->proc); + + if(rb_respond_to(v, s_post_load)) + rb_funcall(v, s_post_load, 0); + + return v; } static VALUE @@ -1273,6 +1283,8 @@ s_getc = rb_intern("getc"); s_read = rb_intern("read"); s_write = rb_intern("write"); + s_pre_dump = rb_intern("_pre_dump"); + s_post_load = rb_intern("_post_load"); rb_define_module_function(rb_mMarshal, "dump", marshal_dump, -1); rb_define_module_function(rb_mMarshal, "load", marshal_load, -1);
-- Nobu Nakada