Skip to content

Commit 71a8f5c

Browse files
authored
Use module context with iterables (#1949)
1 parent 74ce419 commit 71a8f5c

File tree

19 files changed

+57
-57
lines changed

19 files changed

+57
-57
lines changed

src/core/IronPython.Modules/_collections.cs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -56,24 +56,24 @@ public void __init__([ParamDictionary] IDictionary<object, object> dict) {
5656
clear();
5757
}
5858

59-
public void __init__(object iterable) {
59+
public void __init__(CodeContext context, object iterable) {
6060
_maxLen = -1;
6161
clear();
62-
extend(iterable);
62+
extend(context, iterable);
6363
}
6464

65-
public void __init__(object iterable, object maxlen) {
65+
public void __init__(CodeContext context, object iterable, object maxlen) {
6666
_maxLen = VerifyMaxLenValue(maxlen);
6767

6868
clear();
69-
extend(iterable);
69+
extend(context, iterable);
7070
}
7171

72-
public void __init__(object iterable, [ParamDictionary] IDictionary<object, object> dict) {
72+
public void __init__(CodeContext context, object iterable, [ParamDictionary] IDictionary<object, object> dict) {
7373
if (VerifyMaxLen(dict) < 0) {
74-
__init__(iterable);
74+
__init__(context, iterable);
7575
} else {
76-
__init__(iterable, VerifyMaxLen(dict));
76+
__init__(context, iterable, VerifyMaxLen(dict));
7777
}
7878
}
7979

@@ -187,7 +187,7 @@ public void clear() {
187187
public object copy(CodeContext context)
188188
=> __copy__(context);
189189

190-
public void extend(object iterable) {
190+
public void extend(CodeContext context, object iterable) {
191191
// d.extend(d)
192192
if (ReferenceEquals(iterable, this)) {
193193
WalkDeque(idx => {
@@ -197,13 +197,13 @@ public void extend(object iterable) {
197197
return;
198198
}
199199

200-
IEnumerator e = PythonOps.GetEnumerator(iterable);
200+
IEnumerator e = PythonOps.GetEnumerator(context, iterable);
201201
while (e.MoveNext()) {
202202
append(e.Current);
203203
}
204204
}
205205

206-
public void extendleft(object iterable) {
206+
public void extendleft(CodeContext context, object iterable) {
207207
// d.extendleft(d)
208208
if (ReferenceEquals(iterable, this)) {
209209
WalkDeque(idx => {
@@ -213,7 +213,7 @@ public void extendleft(object iterable) {
213213
return;
214214
}
215215

216-
IEnumerator e = PythonOps.GetEnumerator(iterable);
216+
IEnumerator e = PythonOps.GetEnumerator(context, iterable);
217217
while (e.MoveNext()) {
218218
appendleft(e.Current);
219219
}
@@ -511,7 +511,7 @@ public bool __contains__(CodeContext/*!*/ context, object key) {
511511
public object __copy__(CodeContext/*!*/ context) {
512512
if (GetType() == typeof(deque)) {
513513
deque res = new deque(_maxLen);
514-
res.extend(((IEnumerable)this).GetEnumerator());
514+
res.extend(context, ((IEnumerable)this).GetEnumerator());
515515
return res;
516516
} else {
517517
return PythonCalls.Call(context, DynamicHelpers.GetPythonType(this), ((IEnumerable)this).GetEnumerator());
@@ -564,8 +564,8 @@ public int __len__() {
564564
}
565565

566566
[SpecialName]
567-
public deque InPlaceAdd(object other) {
568-
extend(other);
567+
public deque InPlaceAdd(CodeContext context, object other) {
568+
extend(context, other);
569569
return this;
570570
}
571571

@@ -582,18 +582,18 @@ public static deque Add(CodeContext context, [NotNone] deque x, object y) {
582582
public static deque Add(CodeContext context, [NotNone] deque x, [NotNone] deque y) {
583583
var d = (deque)__new__(context, DynamicHelpers.GetPythonType(x), null, null);
584584
if (x._maxLen > 0) {
585-
d.__init__(x, x._maxLen);
585+
d.__init__(context, x, x._maxLen);
586586
} else {
587-
d.__init__(x);
587+
d.__init__(context, x);
588588
}
589-
d.extend(y);
589+
d.extend(context, y);
590590
return d;
591591
}
592592

593593
private static deque MultiplyWorker(deque self, int count) {
594594
var d = new deque(self._maxLen);
595595
if (count <= 0 || self._itemCnt == 0) return d;
596-
d.extend(self);
596+
d.extend(DefaultContext.Default, self); // TODO: context
597597
if (count == 1) return d;
598598

599599
if (d._maxLen < 0 || d._itemCnt * count <= d._maxLen) {

src/core/IronPython.Modules/_functools.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public static class FunctionTools {
2727
public const string __doc__ = "provides functionality for manipulating callable objects";
2828

2929
public static object? reduce(CodeContext/*!*/ context, SiteLocalStorage<CallSite<Func<CallSite, CodeContext, object?, object?, object?, object?>>> siteData, object? func, object? seq) {
30-
IEnumerator i = PythonOps.GetEnumerator(seq);
30+
IEnumerator i = PythonOps.GetEnumerator(context, seq);
3131
if (!i.MoveNext()) {
3232
throw PythonOps.TypeError("reduce() of empty sequence with no initial value");
3333
}
@@ -43,7 +43,7 @@ public static class FunctionTools {
4343
}
4444

4545
public static object? reduce(CodeContext/*!*/ context, SiteLocalStorage<CallSite<Func<CallSite, CodeContext, object?, object?, object?, object?>>> siteData, object? func, object? seq, object? initializer) {
46-
IEnumerator i = PythonOps.GetEnumerator(seq);
46+
IEnumerator i = PythonOps.GetEnumerator(context, seq);
4747
EnsureReduceData(context, siteData);
4848

4949
CallSite<Func<CallSite, CodeContext, object?, object?, object?, object?>> site = siteData.Data;

src/core/IronPython.Modules/_heapq.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public static PythonList nlargest(CodeContext/*!*/ context, int n, object? itera
8787
}
8888

8989
PythonList ret = new PythonList(Math.Min(n, 4000)); // don't allocate anything too huge
90-
IEnumerator en = PythonOps.GetEnumerator(iterable);
90+
IEnumerator en = PythonOps.GetEnumerator(context, iterable);
9191

9292
// populate list with first n items
9393
for (int i = 0; i < n; i++) {
@@ -120,7 +120,7 @@ public static PythonList nsmallest(CodeContext/*!*/ context, int n, object? iter
120120
}
121121

122122
PythonList ret = new PythonList(Math.Min(n, 4000)); // don't allocate anything too huge
123-
IEnumerator en = PythonOps.GetEnumerator(iterable);
123+
IEnumerator en = PythonOps.GetEnumerator(context, iterable);
124124

125125
// populate list with first n items
126126
for (int i = 0; i < n; i++) {

src/core/IronPython.Modules/_operator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ public static bool contains(CodeContext/*!*/ context, object? a, object? b) {
275275
}
276276

277277
public static int countOf(CodeContext/*!*/ context, object? a, object? b) {
278-
System.Collections.IEnumerator e = PythonOps.GetEnumerator(a);
278+
System.Collections.IEnumerator e = PythonOps.GetEnumerator(context, a);
279279
int count = 0;
280280
while (e.MoveNext()) {
281281
if (PythonOps.IsOrEqualsRetBool(context, e.Current, b)) {
@@ -294,7 +294,7 @@ public static object getitem(CodeContext/*!*/ context, object? a, object? b) {
294294
}
295295

296296
public static int indexOf(CodeContext/*!*/ context, object? a, object? b) {
297-
System.Collections.IEnumerator e = PythonOps.GetEnumerator(a);
297+
System.Collections.IEnumerator e = PythonOps.GetEnumerator(context, a);
298298
int index = 0;
299299
while (e.MoveNext()) {
300300
if (PythonOps.IsOrEqualsRetBool(context, e.Current, b)) {

src/core/IronPython.Modules/array.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,8 @@ public void extend(object? iterable) {
326326
}
327327
}
328328

329-
public void fromlist([NotNone] PythonList iterable) {
330-
IEnumerator ie = PythonOps.GetEnumerator(iterable);
329+
public void fromlist(CodeContext context, [NotNone] PythonList iterable) {
330+
IEnumerator ie = PythonOps.GetEnumerator(context, iterable);
331331

332332
List<object> items = new List<object>();
333333
while (ie.MoveNext()) {

src/core/IronPython.Modules/select.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ private static void ProcessSocketSequence(CodeContext context, object sequence,
9090
socketToOriginal = new Dictionary<Socket, object>();
9191
socketList = new PythonList();
9292

93-
IEnumerator cursor = PythonOps.GetEnumerator(sequence);
93+
IEnumerator cursor = PythonOps.GetEnumerator(context, sequence);
9494
while (cursor.MoveNext()) {
9595
object original = cursor.Current;
9696
Socket socket = ObjectToSocket(context, original);

src/core/IronPython/Modules/Builtin.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,7 @@ public static object locals(CodeContext/*!*/ context) {
768768
private static readonly object UndefinedKeywordArgument = new object();
769769

770770
public static object? max(CodeContext/*!*/ context, object? x) {
771-
IEnumerator i = PythonOps.GetEnumerator(x);
771+
IEnumerator i = PythonOps.GetEnumerator(context, x);
772772
if (!i.MoveNext())
773773
throw PythonOps.ValueError("max() arg is an empty sequence");
774774
object? ret = i.Current;
@@ -804,7 +804,7 @@ public static object locals(CodeContext/*!*/ context) {
804804
}
805805

806806
public static object? max(CodeContext/*!*/ context, object? x, [ParamDictionary] IDictionary<string, object?> dict) {
807-
IEnumerator i = PythonOps.GetEnumerator(x);
807+
IEnumerator i = PythonOps.GetEnumerator(context, x);
808808

809809
var kwargTuple = GetMaxKwArg(dict, isDefaultAllowed: true);
810810
object? method = kwargTuple.Item1;
@@ -881,7 +881,7 @@ public static object locals(CodeContext/*!*/ context) {
881881
}
882882

883883
public static object? min(CodeContext/*!*/ context, object? x) {
884-
IEnumerator i = PythonOps.GetEnumerator(x);
884+
IEnumerator i = PythonOps.GetEnumerator(context, x);
885885
if (!i.MoveNext()) {
886886
throw PythonOps.ValueError("empty sequence");
887887
}
@@ -915,7 +915,7 @@ public static object locals(CodeContext/*!*/ context) {
915915
}
916916

917917
public static object? min(CodeContext/*!*/ context, object? x, [ParamDictionary] IDictionary<string, object?> dict) {
918-
IEnumerator i = PythonOps.GetEnumerator(x);
918+
IEnumerator i = PythonOps.GetEnumerator(context, x);
919919
var kwargTuple = GetMinKwArg(dict, isDefaultAllowed: true);
920920
object? method = kwargTuple.Item1;
921921
object? def = kwargTuple.Item2;
@@ -1371,7 +1371,7 @@ public static PythonList sorted(CodeContext/*!*/ context,
13711371
object? iterable,
13721372
[ParamDictionary] IDictionary<string, object> kwArgs) {
13731373

1374-
IEnumerator iter = PythonOps.GetEnumerator(iterable);
1374+
IEnumerator iter = PythonOps.GetEnumerator(context, iterable);
13751375
PythonList l = new PythonList(10);
13761376
while (iter.MoveNext()) {
13771377
l.AddNoLock(iter.Current);
@@ -1395,7 +1395,7 @@ public static PythonList sorted(CodeContext/*!*/ context,
13951395
}
13961396

13971397
public static object? sum(CodeContext/*!*/ context, object? sequence, object? start) {
1398-
IEnumerator i = PythonOps.GetEnumerator(sequence);
1398+
IEnumerator i = PythonOps.GetEnumerator(context, sequence);
13991399

14001400
ValidateSumStart(start);
14011401

src/core/IronPython/Runtime/Binding/PythonBinaryOperationBinder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ private object ListAdd(CallSite site, object self, object other) {
567567
private object ListAddAssign(CallSite site, object self, object other) {
568568
if (self != null && self.GetType() == typeof(PythonList) &&
569569
other != null && other.GetType() == typeof(PythonList)) {
570-
return ((PythonList)self).InPlaceAdd(other);
570+
return ((PythonList)self).InPlaceAdd(DefaultContext.Default, other);
571571
}
572572

573573
return ((CallSite<Func<CallSite, object, object, object>>)site).Update(site, self, other);

src/core/IronPython/Runtime/ByteArray.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -585,8 +585,8 @@ public bool isupper() {
585585
/// in the sequence seq. The separator between elements is the
586586
/// string providing this method
587587
/// </summary>
588-
public ByteArray join(object? iterable) {
589-
IEnumerator seq = PythonOps.GetEnumerator(iterable);
588+
public ByteArray join(CodeContext context, object? iterable) {
589+
IEnumerator seq = PythonOps.GetEnumerator(context, iterable);
590590
if (!seq.MoveNext()) {
591591
return new ByteArray();
592592
}

src/core/IronPython/Runtime/Bytes.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -456,8 +456,8 @@ public int index(BigInteger @byte, object? start, object? end)
456456
/// in the sequence seq. The separator between elements is the
457457
/// string providing this method
458458
/// </summary>
459-
public Bytes join(object? iterable) {
460-
IEnumerator seq = PythonOps.GetEnumerator(iterable);
459+
public Bytes join(CodeContext context, object? iterable) {
460+
IEnumerator seq = PythonOps.GetEnumerator(context, iterable);
461461
if (!seq.MoveNext()) {
462462
return Empty;
463463
}

0 commit comments

Comments
 (0)