Skip to content

Commit

Permalink
Marshal.WriteObject was writing serialization data which includes ins…
Browse files Browse the repository at this point in the history
…tance variables, but the end of MarshalWriter.WriteAnObject was writing instance data as well. Removed writing of serialization data

TimeOps.load had a bug causing local time to be loaded as utc time.
Added building of IronPython to irtests.bat since it is needed for the language interop tests
  • Loading branch information
Shri Borde committed Mar 24, 2009
1 parent d522059 commit 79298ef
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 61 deletions.

This file was deleted.

Expand Up @@ -77,20 +77,14 @@ def _dump(depth); 10; end
Marshal.dump(obj).should == "#{mv+nv}o:\x0BObject\x06:\x09@str[\x09:\x07so;\x07\"\x07hi@\x07"
end

it "dumps an extended_user_regexp having ivar" do
r = UserRegexp.new('').extend(Meths)
r.instance_variable_set(:@noise, 'much')
Marshal.dump(r).should == "#{mv+nv}Ie:\x0AMethsC:\x0FUserRegexp/\x00\x00\x06:\x0B@noise\"\x09much"
end

it "raises a TypeError with hash having default proc" do
lambda { Marshal.dump(Hash.new {}) }.should raise_error(TypeError)
end

it "dumps an extended_user_hash_default" do
h = UserHash.new(:Meths).extend(Meths)
h['three'] = 3
Marshal.dump(h).should == "#{mv+nv}e:\x0AMethsC:\x0DUserHash}\x06\"\x0Athreei\x08;\x00"
Marshal.dump(h).should == "#{mv+nv}Ie:\x0AMethsC:\x0DUserHash}\x06\"\x0Athreei\x08;\x00\006:\a@ai\006"
end

it "dumps an extended_user_hash with a parameter to initialize" do
Expand Down
@@ -1,18 +1,28 @@
class UserDefined

class UserOuter
class Nested
def ==(other)
other.kind_of? self.class
end
end
end

class UserSimple
attr_reader :a, :b

def initialize
@a = 'stuff'
@b = @a
end

def ==(other)
self.class === other and
@a == other.a and
@b == other.b
end

end

class UserDefined < UserSimple
def _dump(depth)
Marshal.dump [@a, @b]
end
Expand All @@ -26,13 +36,6 @@ def self._load(data)

obj
end

def ==(other)
self.class === other and
@a == other.a and
@b == other.b
end

end

class UserDefinedWithIvar
Expand Down Expand Up @@ -101,10 +104,21 @@ def ==(other)
end
end

module AnAttribute
attr :a

def initialize(*args)
@a = 1
super
end
end

class UserArray < Array
include AnAttribute
end

class UserHash < Hash
include AnAttribute
end

class UserHashInitParams < Hash
Expand All @@ -117,9 +131,11 @@ class UserObject
end

class UserRegexp < Regexp
include AnAttribute
end

class UserString < String
include AnAttribute
end

module Meths
Expand Down Expand Up @@ -161,10 +177,10 @@ module MarshalSpec
"\004\b\"\002,\001#{'big' * 100}"],
"String extended" => [''.extend(Meths), # TODO: check for module on load
"\004\be:\nMeths\"\000"],
"String subclass" => [UserString.new,
"\004\bC:\017UserString\"\000"],
"String subclass" => [UserString.new("hello"),
"\004\bIC:\017UserString\"\nhello\006:\a@ai\006"],
"String subclass extended" => [UserString.new.extend(Meths),
"\004\be:\nMethsC:\017UserString\"\000"],
"\004\bIe:\nMethsC:\017UserString\"\000\006:\a@ai\006"],
"Symbol small" => [:big,
"\004\b:\010big"],
"Symbol big" => [('big' * 100).to_sym,
Expand Down Expand Up @@ -199,8 +215,11 @@ module MarshalSpec
"\004\bc\vString"],
"Module Marshal" => [Marshal,
"\004\bm\fMarshal"],
"Module nested" => [UserDefined::Nested.new,
"\004\bo:\030UserDefined::Nested\000"],
"User type" => [UserSimple.new,
"\004\bo:\017UserSimple\a:\a@b\"\nstuff:\a@a@\006",
{ :a => "stuff", :b => "stuff" }],
"Module nested" => [UserOuter::Nested.new,
"\004\bo:\026UserOuter::Nested\000"],
"_dump object" => [UserDefinedWithIvar.new,
"\004\bu:\030UserDefinedWithIvar5\004\b[\bI\"\nstuff\006:\t@foo:\030UserDefinedWithIvar\"\tmore@\a"],
"_dump object extended" => [UserDefined.new.extend(Meths),
Expand All @@ -210,7 +229,9 @@ module MarshalSpec
"Regexp" => [/\A.\Z/,
"\004\b/\n\\A.\\Z\000"],
"Regexp subclass /i" => [UserRegexp.new('', Regexp::IGNORECASE),
"\004\bC:\017UserRegexp/\000\001"],
"\004\bIC:\017UserRegexp/\000\001\006:\a@ai\006"],
"Regexp subclass extended" => [UserRegexp.new('').extend(Meths),
"\004\bIe:\nMethsC:\017UserRegexp/\000\000\006:\a@ai\006"],
"Float 0.0" => [0.0,
"\004\bf\0060"],
"Float -0.0" => [-0.0,
Expand All @@ -223,12 +244,12 @@ module MarshalSpec
"\004\bf\0061"],
"Hash" => [Hash.new,
"\004\b{\000"],
"Hash subclass" => [UserHash.new,
"\004\bC:\rUserHash{\000"],
"Hash subclass" => [UserHash.new.merge({:hi => "hi"}),
"\004\bIC:\rUserHash{\006:\ahi\"\ahi\006:\a@ai\006"],
"Array" => [Array.new,
"\004\b[\000"],
"Array subclass" => [UserArray.new,
"\004\bC:\016UserArray[\000"],
"Array subclass" => [UserArray.new([100, 200]),
"\004\bIC:\016UserArray[\aiii\001\310\006:\a@ai\006"],
"Struct" => [Struct::Pyramid.new,
"\004\bS:\024Struct::Pyramid\000"],
}
Expand Down
Expand Up @@ -89,7 +89,7 @@
new_obj.instance_variable_get(:@noise).should == 'much'
new_obj_metaclass_ancestors = class << new_obj; ancestors; end
new_obj_metaclass_ancestors.first(3).should ==
[Meths, UserRegexp, Regexp]
[Meths, UserRegexp, AnAttribute]
end

it "loads a Float NaN" do
Expand Down Expand Up @@ -206,17 +206,26 @@
lambda { Marshal.load marshal_data }.should raise_error(TypeError)
end

it "raises ArgumentError on loading from an empty string" do
lambda { Marshal.load("") }.should raise_error(ArgumentError)
end

it "raises EOFError on loading an empty file" do
temp_file = tmp("marshal.rubinius.tmp.#{Process.pid}")
file = File.new(temp_file, "w+")
begin
# TODO: This should be in an ensure block, but because of a bug in
# Rubinius that can't be done yet.
File.unlink(temp_file)

lambda { Marshal.load(file) }.should raise_error(EOFError)

compliant_on :rubinius do
# TODO: This should be in an ensure block, but because of a bug in
# Rubinius that can't be done yet.
File.unlink(temp_file)
end
ensure
file.close
not_compliant_on :rubinius do
File.unlink(temp_file)
end
end
end

Expand Down
Expand Up @@ -2,10 +2,13 @@
require File.dirname(__FILE__) + '/fixtures/methods'

describe "Time#_load" do
before :each do
@t = Time.local(2000, 1, 15, 20, 1, 1)
end

ruby_bug("http://redmine.ruby-lang.org/issues/show/627", "1.8.7") do
it "loads a time object in the new format" do
t = Time.local(2000, 1, 15, 20, 1, 1)
t = t.gmtime
t = @t.gmtime

high = 1 << 31 |
(t.gmt? ? 1 : 0) << 30 |
Expand All @@ -32,4 +35,8 @@

Time._load([high, low].pack("LL")).should == t
end

it "loads local time" do
Time._load("\004\002\031\200\000\000\020\004").should == @t
end
end
Expand Up @@ -278,37 +278,23 @@ class SubclassData {
}
}

private void WriteRange(Range/*!*/ range) {
_writer.Write((byte)'o');
WriteSymbol("Range");
WriteInt32(3);
WriteSymbol("begin");
WriteAnObject(range.Begin);
WriteSymbol("end");
WriteAnObject(range.End);
WriteSymbol("excl");
WriteAnObject(range.ExcludeEnd);
}

private void WriteObject(object/*!*/ obj) {
_writer.Write((byte)'o');
RubyClass theClass = _context.GetClassOf(obj);
TestForAnonymous(theClass);
WriteSymbol(theClass.Name);

#if !SILVERLIGHT
ISerializable serializableObj = (obj as ISerializable);
if (serializableObj != null) {
SerializationInfo info = new SerializationInfo(theClass.GetUnderlyingSystemType(), new FormatterConverter());
serializableObj.GetObjectData(info, _streamingContext);
int count = info.MemberCount;
try {
// We need this attribute for CLR serialization but it's not compatible with MRI serialization
// Unfortunately, there's no way to test for a value without either iterating over all values
// or throwing an exception if it's not present
if (info.GetValue("#class", typeof(RubyClass)) != null) {
count--;
}
} catch (Exception) {
}
WriteInt32(count);
foreach (SerializationEntry entry in info) {
if (!entry.Name.Equals("#class")) {
WriteSymbol(entry.Name);
WriteAnObject(entry.Value);
}
}
return;
}
#endif
}

private void WriteUsingDump(object/*!*/ obj) {
Expand Down Expand Up @@ -443,6 +429,8 @@ class SubclassData {
WriteModule((RubyModule)obj);
} else if (obj is RubyStruct) {
WriteStruct((RubyStruct)obj);
} else if (obj is Range) {
WriteRange((Range)obj);
} else {
if (writeInstanceData) {
// Overwrite the "I"; we always have instance data
Expand Down
Expand Up @@ -274,7 +274,7 @@ public static class TimeOps {
try {
DateTime result = new DateTime(year, month, day, hour, minute, second, DateTimeKind.Utc);
result = result.AddTicks(usec * 10L);
if (isUtc) {
if (!isUtc) {
result = result.ToLocalTime();
}
return result;
Expand Down
7 changes: 7 additions & 0 deletions Merlin/Main/Languages/Ruby/Scripts/irtests.bat
@@ -1,5 +1,11 @@
@setlocal

msbuild.exe %MERLIN_ROOT%\Languages\Ruby\Ruby.sln /p:Configuration="Debug"
if not %ERRORLEVEL%==0 goto END
REM IronPython needs to be in sync for the language interop tests
msbuild.exe %MERLIN_ROOT%\Languages\IronPython\IronPython.sln /p:Configuration="Debug"
if not %ERRORLEVEL%==0 goto END

start "Smoke Tests" %MERLIN_ROOT%\Languages\Ruby\Tests\Scripts\irtest.bat

start "Legacy Tests" %MERLIN_ROOT%\Languages\Ruby\Tests\run.bat
Expand All @@ -17,3 +23,4 @@ start "Command Line RubySpec tests" mspec ci -fd -V :cli
%MERLIN_ROOT%\Bin\Debug\ipy.exe %MERLIN_ROOT%\Scripts\Python\GenerateSystemCoreCsproj.py
)

:END

0 comments on commit 79298ef

Please sign in to comment.