[#688] mkmf.rb - add files to clean and distclean targets — Michal Rokos <michal@...>

Hi,

25 messages 2003/01/15
[#722] Re: [RFC] mkmf.rb - add files to clean and distclean targets — Mathieu Bouchard <matju@...> 2003/01/20

On Thu, 16 Jan 2003, Michal Rokos wrote:

[#740] Re: [RFC] mkmf.rb - add files to clean and distclean targets — matz@... (Yukihiro Matsumoto) 2003/01/21

Hi,

[#724] Symbols: More Functionality Wanted — Ryan Pavlik <rpav@...>

I've been discussing this for a bit on #ruby-lang on OPN (or freenode or

23 messages 2003/01/20
[#728] Re: Symbols: More Functionality Wanted — matz@... (Yukihiro Matsumoto) 2003/01/20

Hi,

[#743] Re: Symbols: More Functionality Wanted — "Pit Capitain" <pit@...> 2003/01/21

On 20 Jan 2003 at 15:49, Yukihiro Matsumoto wrote:

[#767] Re: Symbols: More Functionality Wanted — Mathieu Bouchard <matju@...> 2003/01/22

[#768] Re: Symbols: More Functionality Wanted — dblack@... 2003/01/22

Hi --

[#779] Re: Symbols: More Functionality Wanted — Gavin Sinclair <gsinclair@...> 2003/01/23

On Thursday, January 23, 2003, 6:28:04 AM, dblack wrote:

Forward: Marshal patch

From: nobu.nokada@...
Date: 2003-01-16 01:21:36 UTC
List: ruby-core #690
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

In This Thread

Prev Next