Skip to content

Commit 775bfb3

Browse files
committed
Update to Java commit 25e8f4e: (2025.08.25): CLJ-2916 - LazySeq - realize before serializing and do not serialize IFn. -- NOT COMPLETED
1 parent 4f9e58f commit 775bfb3

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

Clojure/Clojure/Lib/LazySeq.cs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
using System;
1616
using System.Collections;
17-
using System.Runtime.CompilerServices;
1817
using System.Collections.Generic;
1918
using System.Threading;
2019

@@ -25,6 +24,12 @@ namespace clojure.lang
2524
{
2625
#region Data
2726

27+
// TODO: Making this field non-serialized is only part of the solution to CLJ-2916 LazySeq - realize before serializing and do not serialize IFn.
28+
// Unfortunately, making the LazySeq realize before serializing requires implementatin ISerializable, then making Obj implement it also.
29+
// And doing that causes 49 errors in the test suite -- we need to add an additional constructor and probably also GetObjectData for every class derived from Obj.
30+
// That's too much. Defer this until we decide what to do about BinaryFormatter being declared obsolete/unsafe.
31+
32+
[NonSerialized]
2833
private IFn _fn;
2934
private object _sv;
3035
private ISeq _s;
@@ -54,7 +59,7 @@ private LazySeq(IPersistentMap meta, ISeq seq)
5459
// MUST be locked when called
5560
private void Force()
5661
{
57-
if ( _fn != null )
62+
if (_fn != null)
5863
{
5964
_sv = _fn.invoke();
6065
_fn = null;
@@ -100,7 +105,7 @@ private object Unwrap(Object ls)
100105
private void Realize()
101106
{
102107
var lk = _lock;
103-
if ( lk != null)
108+
if (lk != null)
104109
{
105110
lk.EnterWriteLock();
106111
try
@@ -154,7 +159,7 @@ public override IObj withMeta(IPersistentMap meta)
154159
if (_meta == meta)
155160
return this;
156161

157-
return new LazySeq(meta,seq());
162+
return new LazySeq(meta, seq());
158163
}
159164

160165
#endregion
@@ -173,7 +178,7 @@ public ISeq seq()
173178
}
174179

175180
#endregion
176-
181+
177182
#region IPersistentCollection Members
178183

179184
public int count()
@@ -204,7 +209,7 @@ public bool equiv(object o)
204209
}
205210

206211
#endregion
207-
212+
208213
#region ISeq Members
209214

210215
public object first()
@@ -333,7 +338,7 @@ public object this[int index]
333338
get
334339
{
335340
if (index < 0)
336-
throw new ArgumentOutOfRangeException(nameof(index),"Index must be non-negative.");
341+
throw new ArgumentOutOfRangeException(nameof(index), "Index must be non-negative.");
337342

338343
ISeq s = seq();
339344
for (int i = 0; s != null; s = s.next(), i++)
@@ -358,7 +363,7 @@ public void CopyTo(object[] array, int arrayIndex)
358363
if (arrayIndex < 0)
359364
throw new ArgumentOutOfRangeException(nameof(arrayIndex), "must be non-negative.");
360365
if (array.Rank > 1)
361-
throw new ArgumentException("must not be multidimensional",nameof(array));
366+
throw new ArgumentException("must not be multidimensional", nameof(array));
362367
if (arrayIndex >= array.Length)
363368
throw new ArgumentException("must be less than the length", nameof(arrayIndex));
364369
if (count() > array.Length - arrayIndex)
@@ -374,7 +379,7 @@ public void CopyTo(Array array, int index)
374379
if (array == null)
375380
throw new ArgumentNullException(nameof(array));
376381
if (index < 0)
377-
throw new ArgumentOutOfRangeException(nameof(index),"must be non-negative.");
382+
throw new ArgumentOutOfRangeException(nameof(index), "must be non-negative.");
378383
if (array.Rank > 1)
379384
throw new ArgumentException("must not be multidimensional.", nameof(array));
380385
if (index >= array.Length)

0 commit comments

Comments
 (0)