From 01a514494d065bb0bd367afbe9604891cc188db8 Mon Sep 17 00:00:00 2001 From: Kevin Clark Date: Wed, 18 Jun 2008 01:14:36 +0000 Subject: [PATCH] Fix default values of non-primitive types being shared between struct instances (THRIFT-4) git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@668989 13f79535-47bb-0310-9956-ffa450edef68 --- lib/rb/lib/thrift/struct.rb | 2 +- lib/rb/spec/struct_spec.rb | 16 +++++++--------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/lib/rb/lib/thrift/struct.rb b/lib/rb/lib/thrift/struct.rb index 934d0b7f..5a782ca5 100644 --- a/lib/rb/lib/thrift/struct.rb +++ b/lib/rb/lib/thrift/struct.rb @@ -4,7 +4,7 @@ module Thrift module Struct def initialize(d={}) each_field do |fid, type, name, default| - instance_variable_set("@#{name}", d[name.to_s] || d[name.intern] || default) + instance_variable_set("@#{name}", d[name.to_s] || d[name.intern] || (default.dup rescue default)) end end diff --git a/lib/rb/spec/struct_spec.rb b/lib/rb/spec/struct_spec.rb index 5e21593f..4ae7d426 100644 --- a/lib/rb/spec/struct_spec.rb +++ b/lib/rb/spec/struct_spec.rb @@ -37,15 +37,13 @@ class ThriftStructSpec < Spec::ExampleGroup end it "should not share default values between instances" do - pending do - begin - struct = Foo.new - struct.ints << 17 - Foo.new.ints.should == [1,2,2,3] - ensure - # ensure no leakage to other tests - Foo::FIELDS[4][:default] = [1,2,2,3] - end + begin + struct = Foo.new + struct.ints << 17 + Foo.new.ints.should == [1,2,2,3] + ensure + # ensure no leakage to other tests + Foo::FIELDS[4][:default] = [1,2,2,3] end end -- 2.17.1