From 81a0c608eb73f1a250ec9ec11107280b8d086ef8 Mon Sep 17 00:00:00 2001 From: nobu Date: Mon, 4 Jun 2012 02:40:30 +0000 Subject: 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 --- ext/-test-/marshal/compat/extconf.rb | 1 + ext/-test-/marshal/compat/usrcompat.c | 32 ++++++++++++++++++++++++++++++++ ext/-test-/marshal/usr/extconf.rb | 1 + ext/-test-/marshal/usr/usrmarshal.c | 35 +++++++++++++++++++++++++++++++++++ 4 files changed, 69 insertions(+) create mode 100644 ext/-test-/marshal/compat/extconf.rb create mode 100644 ext/-test-/marshal/compat/usrcompat.c create mode 100644 ext/-test-/marshal/usr/extconf.rb create mode 100644 ext/-test-/marshal/usr/usrmarshal.c (limited to 'ext/-test-/marshal') diff --git a/ext/-test-/marshal/compat/extconf.rb b/ext/-test-/marshal/compat/extconf.rb new file mode 100644 index 0000000000..bb11ebfb8c --- /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 0000000000..f812df5631 --- /dev/null +++ b/ext/-test-/marshal/compat/usrcompat.c @@ -0,0 +1,32 @@ +#include + +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 0000000000..c662b23dd5 --- /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 0000000000..b30bd52c13 --- /dev/null +++ b/ext/-test-/marshal/usr/usrmarshal.c @@ -0,0 +1,35 @@ +#include + +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); +} -- cgit v1.2.3