summaryrefslogtreecommitdiff
path: root/ext/-test-/marshal
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-06-04 02:40:30 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-06-04 02:40:30 +0000
commit81a0c608eb73f1a250ec9ec11107280b8d086ef8 (patch)
treef790c121eede11e7838189e798ffff60038b97da /ext/-test-/marshal
parent2493e48d40bb984f315be0e478bf3b9f0dec588c (diff)
compatible loader
* marshal.c (r_object0): also load TYPE_USRMARSHAL, TYPE_DATA using compatible loader. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35898 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/-test-/marshal')
-rw-r--r--ext/-test-/marshal/compat/extconf.rb1
-rw-r--r--ext/-test-/marshal/compat/usrcompat.c32
-rw-r--r--ext/-test-/marshal/usr/extconf.rb1
-rw-r--r--ext/-test-/marshal/usr/usrmarshal.c35
4 files changed, 69 insertions, 0 deletions
diff --git a/ext/-test-/marshal/compat/extconf.rb b/ext/-test-/marshal/compat/extconf.rb
new file mode 100644
index 0000000..bb11ebf
--- /dev/null
+++ b/ext/-test-/marshal/compat/extconf.rb
@@ -0,0 +1 @@
+create_makefile("-test-/marshal/compat")
diff --git a/ext/-test-/marshal/compat/usrcompat.c b/ext/-test-/marshal/compat/usrcompat.c
new file mode 100644
index 0000000..f812df5
--- /dev/null
+++ b/ext/-test-/marshal/compat/usrcompat.c
@@ -0,0 +1,32 @@
+#include <ruby.h>
+
+static VALUE
+usr_dumper(VALUE self)
+{
+ return self;
+}
+
+static VALUE
+usr_loader(VALUE self, VALUE m)
+{
+ VALUE val = rb_ivar_get(m, rb_intern("@value"));
+ *(int *)DATA_PTR(self) = NUM2INT(val);
+ return self;
+}
+
+static VALUE
+compat_mload(VALUE self, VALUE data)
+{
+ rb_ivar_set(self, rb_intern("@value"), data);
+ return self;
+}
+
+void
+Init_compat(void)
+{
+ VALUE newclass = rb_path2class("Bug::Marshal::UsrMarshal");
+ VALUE oldclass = rb_define_class_under(newclass, "compat", rb_cObject);
+
+ rb_define_method(oldclass, "marshal_load", compat_mload, 1);
+ rb_marshal_define_compat(newclass, oldclass, usr_dumper, usr_loader);
+}
diff --git a/ext/-test-/marshal/usr/extconf.rb b/ext/-test-/marshal/usr/extconf.rb
new file mode 100644
index 0000000..c662b23
--- /dev/null
+++ b/ext/-test-/marshal/usr/extconf.rb
@@ -0,0 +1 @@
+create_makefile("-test-/marshal/usr")
diff --git a/ext/-test-/marshal/usr/usrmarshal.c b/ext/-test-/marshal/usr/usrmarshal.c
new file mode 100644
index 0000000..b30bd52
--- /dev/null
+++ b/ext/-test-/marshal/usr/usrmarshal.c
@@ -0,0 +1,35 @@
+#include <ruby.h>
+
+static VALUE
+usr_alloc(VALUE klass)
+{
+ int *p;
+ return Data_Make_Struct(klass, int, 0, RUBY_DEFAULT_FREE, p);
+}
+
+static VALUE
+usr_init(VALUE self, VALUE val)
+{
+ *(int *)DATA_PTR(self) = NUM2INT(val);
+ return self;
+}
+
+static VALUE
+usr_value(VALUE self)
+{
+ int val = *(int *)DATA_PTR(self);
+ return INT2NUM(val);
+}
+
+void
+Init_usr(void)
+{
+ VALUE mMarshal = rb_define_module_under(rb_define_module("Bug"), "Marshal");
+ VALUE newclass = rb_define_class_under(mMarshal, "UsrMarshal", rb_cObject);
+
+ rb_define_alloc_func(newclass, usr_alloc);
+ rb_define_method(newclass, "initialize", usr_init, 1);
+ rb_define_method(newclass, "value", usr_value, 0);
+ rb_define_method(newclass, "marshal_load", usr_init, 1);
+ rb_define_method(newclass, "marshal_dump", usr_value, 0);
+}