From 72823fee04a9e48e3bd5edf7fdd4b57b42ecb174 Mon Sep 17 00:00:00 2001 From: leandromoh Date: Wed, 1 May 2019 16:48:40 -0300 Subject: [PATCH 1/4] add validation for dispose once --- MoreLinq.Test/TestingSequence.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/MoreLinq.Test/TestingSequence.cs b/MoreLinq.Test/TestingSequence.cs index 6abdac68e..e0c789aa7 100644 --- a/MoreLinq.Test/TestingSequence.cs +++ b/MoreLinq.Test/TestingSequence.cs @@ -67,7 +67,11 @@ public IEnumerator GetEnumerator() Assert.That(_sequence, Is.Not.Null, "LINQ operators should not enumerate a sequence more than once."); var enumerator = _sequence.GetEnumerator().AsWatchtable(); _disposed = false; - enumerator.Disposed += delegate { _disposed = true; }; + enumerator.Disposed += delegate + { + Assert.That(_disposed, Is.False, "LINQ operators should not dispose a sequence more than once."); + _disposed = true; + }; enumerator.MoveNextCalled += delegate { MoveNextCallCount++; }; _sequence = null; return enumerator; From e529fc1f4052fc2585c4d59344657db4f3b81fde Mon Sep 17 00:00:00 2001 From: leandromoh Date: Wed, 1 May 2019 16:48:53 -0300 Subject: [PATCH 2/4] flatten fix --- MoreLinq/Flatten.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/MoreLinq/Flatten.cs b/MoreLinq/Flatten.cs index 1369a6945..e98466c3e 100644 --- a/MoreLinq/Flatten.cs +++ b/MoreLinq/Flatten.cs @@ -123,6 +123,7 @@ public static IEnumerable Flatten(this IEnumerable source, Func Date: Wed, 1 May 2019 16:49:09 -0300 Subject: [PATCH 3/4] zipimpl fix --- MoreLinq/ZipImpl.cs | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/MoreLinq/ZipImpl.cs b/MoreLinq/ZipImpl.cs index 8341e518e..2005660cb 100644 --- a/MoreLinq/ZipImpl.cs +++ b/MoreLinq/ZipImpl.cs @@ -34,17 +34,19 @@ static IEnumerable ZipImpl( int limit, Folder errorSelector = null) { - IEnumerator e1; - IEnumerator e2; - IEnumerator e3; - IEnumerator e4; + IEnumerator e1 = null; + IEnumerator e2 = null; + IEnumerator e3 = null; + IEnumerator e4 = null; var terminations = 0; - using (e1 = s1 .GetEnumerator()) - using (e2 = s2 .GetEnumerator()) - using (e3 = s3?.GetEnumerator()) - using (e4 = s4?.GetEnumerator()) + try { + e1 = s1 .GetEnumerator(); + e2 = s2 .GetEnumerator(); + e3 = s3?.GetEnumerator(); + e4 = s4?.GetEnumerator(); + while (true) { var n = 0; @@ -59,6 +61,13 @@ static IEnumerable ZipImpl( yield break; } } + finally + { + e1?.Dispose(); + e2?.Dispose(); + e3?.Dispose(); + e4?.Dispose(); + } T Read(ref IEnumerator e, int n) { From 4022663cf5e7929d7e59d8eb2cea7c01cebb9769 Mon Sep 17 00:00:00 2001 From: leandromoh Date: Wed, 1 May 2019 16:53:59 -0300 Subject: [PATCH 4/4] removed trailing spaces --- MoreLinq.Test/TestingSequence.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/MoreLinq.Test/TestingSequence.cs b/MoreLinq.Test/TestingSequence.cs index e0c789aa7..bb805c48e 100644 --- a/MoreLinq.Test/TestingSequence.cs +++ b/MoreLinq.Test/TestingSequence.cs @@ -67,10 +67,10 @@ public IEnumerator GetEnumerator() Assert.That(_sequence, Is.Not.Null, "LINQ operators should not enumerate a sequence more than once."); var enumerator = _sequence.GetEnumerator().AsWatchtable(); _disposed = false; - enumerator.Disposed += delegate - { + enumerator.Disposed += delegate + { Assert.That(_disposed, Is.False, "LINQ operators should not dispose a sequence more than once."); - _disposed = true; + _disposed = true; }; enumerator.MoveNextCalled += delegate { MoveNextCallCount++; }; _sequence = null;