Skip to content

Commit 96d2c5c

Browse files
author
Franziska Geiger
committed
Merged master
2 parents 715b2cd + f3c7a51 commit 96d2c5c

File tree

183 files changed

+5631
-3945
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

183 files changed

+5631
-3945
lines changed

graalpython/com.oracle.graal.python.cext/src/tupleobject.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ PyObject* PyTuple_Pack(Py_ssize_t n, ...) {
7373
if (result == NULL) {
7474
return NULL;
7575
}
76-
for (int i = 1; i < polyglot_get_arg_count(); i++) {
77-
PyObject *o = polyglot_get_arg(i);
78-
PyTuple_SetItem(result, i - 1, o);
76+
for (int i = 0; i < n; i++) {
77+
PyObject *o = polyglot_get_arg(i+1);
78+
PyTuple_SetItem(result, i, o);
7979
}
8080
return result;
8181
}

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/datatype/PRangeTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,14 @@ public void loopWithOnlyStop() throws UnexpectedResultException {
7272
TestRoot testRoot = new TestRoot(PythonLanguage.getCurrent());
7373
GetIteratorNode getIter = GetIteratorNode.create();
7474
testRoot.doInsert(getIter);
75-
Object iter = getIter.executeWith(range);
75+
Object iter = getIter.executeWith(null, range);
7676
GetNextNode next = GetNextNode.create();
7777
testRoot.doInsert(next);
7878
IsBuiltinClassProfile errorProfile = IsBuiltinClassProfile.create();
7979

8080
while (true) {
8181
try {
82-
int item = next.executeInt(iter);
82+
int item = next.executeInt(null, iter);
8383
assertEquals(index, item);
8484
} catch (PException e) {
8585
e.expectStopIteration(errorProfile);
@@ -96,14 +96,14 @@ public void loopWithStep() throws UnexpectedResultException {
9696
TestRoot testRoot = new TestRoot(PythonLanguage.getCurrent());
9797
GetIteratorNode getIter = GetIteratorNode.create();
9898
testRoot.doInsert(getIter);
99-
Object iter = getIter.executeWith(range);
99+
Object iter = getIter.executeWith(null, range);
100100
GetNextNode next = GetNextNode.create();
101101
testRoot.doInsert(next);
102102
IsBuiltinClassProfile errorProfile = IsBuiltinClassProfile.create();
103103

104104
while (true) {
105105
try {
106-
int item = next.executeInt(iter);
106+
int item = next.executeInt(null, iter);
107107
assertEquals(index, item);
108108
} catch (PException e) {
109109
e.expectStopIteration(errorProfile);

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/grammar/TestParserTranslator.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
import com.oracle.graal.python.builtins.objects.PNone;
5959
import com.oracle.graal.python.builtins.objects.complex.PComplex;
6060
import com.oracle.graal.python.builtins.objects.dict.PDict;
61+
import com.oracle.graal.python.builtins.objects.function.PArguments;
6162
import com.oracle.graal.python.builtins.objects.list.PList;
6263
import com.oracle.graal.python.builtins.objects.set.PSet;
6364
import com.oracle.graal.python.builtins.objects.tuple.PTuple;
@@ -143,7 +144,7 @@ public Object execute(VirtualFrame frame) {
143144
private Object runInRoot(ExpressionNode expr) {
144145
JUnitRootNode jUnitRootNode = new JUnitRootNode(context.getLanguage(), expr);
145146
RootCallTarget callTarget = Truffle.getRuntime().createCallTarget(jUnitRootNode);
146-
return callTarget.call();
147+
return callTarget.call(PArguments.create());
147148
}
148149

149150
RootNode parse(String src) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ArrayModuleBuiltins.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
5454
import com.oracle.truffle.api.dsl.NodeFactory;
5555
import com.oracle.truffle.api.dsl.Specialization;
56+
import com.oracle.truffle.api.frame.VirtualFrame;
5657

5758
@CoreFunctions(defineModule = "array")
5859
public final class ArrayModuleBuiltins extends PythonBuiltins {
@@ -121,20 +122,20 @@ protected boolean isDoubleArray(String typeCode) {
121122
}
122123

123124
@Specialization(guards = "isByteArray(typeCode)")
124-
PArray arrayByteInitializer(LazyPythonClass cls, @SuppressWarnings("unused") String typeCode, PSequence initializer,
125+
PArray arrayByteInitializer(VirtualFrame frame, LazyPythonClass cls, @SuppressWarnings("unused") String typeCode, PSequence initializer,
125126
@Cached("createCast()") CastToByteNode castToByteNode,
126127
@Cached("create()") GetIteratorNode getIterator,
127128
@Cached("create()") GetNextNode next,
128129
@Cached("create()") IsBuiltinClassProfile errorProfile,
129130
@Cached("create()") SequenceNodes.LenNode lenNode) {
130-
Object iter = getIterator.executeWith(initializer);
131+
Object iter = getIterator.executeWith(frame, initializer);
131132
int i = 0;
132133
byte[] byteArray = new byte[lenNode.execute(initializer)];
133134

134135
while (true) {
135136
Object nextValue;
136137
try {
137-
nextValue = next.execute(iter);
138+
nextValue = next.execute(frame, iter);
138139
} catch (PException e) {
139140
e.expectStopIteration(errorProfile);
140141
break;
@@ -146,20 +147,20 @@ PArray arrayByteInitializer(LazyPythonClass cls, @SuppressWarnings("unused") Str
146147
}
147148

148149
@Specialization(guards = "isIntArray(typeCode)")
149-
PArray arrayIntInitializer(LazyPythonClass cls, @SuppressWarnings("unused") String typeCode, PSequence initializer,
150+
PArray arrayIntInitializer(VirtualFrame frame, LazyPythonClass cls, @SuppressWarnings("unused") String typeCode, PSequence initializer,
150151
@Cached("create()") GetIteratorNode getIterator,
151152
@Cached("create()") GetNextNode next,
152153
@Cached("create()") IsBuiltinClassProfile errorProfile,
153154
@Cached("create()") SequenceNodes.LenNode lenNode) {
154-
Object iter = getIterator.executeWith(initializer);
155+
Object iter = getIterator.executeWith(frame, initializer);
155156
int i = 0;
156157

157158
int[] intArray = new int[lenNode.execute(initializer)];
158159

159160
while (true) {
160161
Object nextValue;
161162
try {
162-
nextValue = next.execute(iter);
163+
nextValue = next.execute(frame, iter);
163164
} catch (PException e) {
164165
e.expectStopIteration(errorProfile);
165166
break;
@@ -175,20 +176,20 @@ PArray arrayIntInitializer(LazyPythonClass cls, @SuppressWarnings("unused") Stri
175176
}
176177

177178
@Specialization(guards = "isLongArray(typeCode)")
178-
PArray arrayLongInitializer(LazyPythonClass cls, @SuppressWarnings("unused") String typeCode, PSequence initializer,
179+
PArray arrayLongInitializer(VirtualFrame frame, LazyPythonClass cls, @SuppressWarnings("unused") String typeCode, PSequence initializer,
179180
@Cached("create()") GetIteratorNode getIterator,
180181
@Cached("create()") GetNextNode next,
181182
@Cached("create()") IsBuiltinClassProfile errorProfile,
182183
@Cached("create()") SequenceNodes.LenNode lenNode) {
183-
Object iter = getIterator.executeWith(initializer);
184+
Object iter = getIterator.executeWith(frame, initializer);
184185
int i = 0;
185186

186187
long[] longArray = new long[lenNode.execute(initializer)];
187188

188189
while (true) {
189190
Object nextValue;
190191
try {
191-
nextValue = next.execute(iter);
192+
nextValue = next.execute(frame, iter);
192193
} catch (PException e) {
193194
e.expectStopIteration(errorProfile);
194195
break;
@@ -204,20 +205,20 @@ PArray arrayLongInitializer(LazyPythonClass cls, @SuppressWarnings("unused") Str
204205
}
205206

206207
@Specialization(guards = "isDoubleArray(typeCode)")
207-
PArray arrayDoubleInitializer(LazyPythonClass cls, @SuppressWarnings("unused") String typeCode, PSequence initializer,
208+
PArray arrayDoubleInitializer(VirtualFrame frame, LazyPythonClass cls, @SuppressWarnings("unused") String typeCode, PSequence initializer,
208209
@Cached("create()") GetIteratorNode getIterator,
209210
@Cached("create()") GetNextNode next,
210211
@Cached("create()") IsBuiltinClassProfile errorProfile,
211212
@Cached("create()") SequenceNodes.LenNode lenNode) {
212-
Object iter = getIterator.executeWith(initializer);
213+
Object iter = getIterator.executeWith(frame, initializer);
213214
int i = 0;
214215

215216
double[] doubleArray = new double[lenNode.execute(initializer)];
216217

217218
while (true) {
218219
Object nextValue;
219220
try {
220-
nextValue = next.execute(iter);
221+
nextValue = next.execute(frame, iter);
221222
} catch (PException e) {
222223
e.expectStopIteration(errorProfile);
223224
break;

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/AtexitModuleBuiltins.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,23 @@
4242

4343
import java.util.List;
4444

45+
import com.oracle.graal.python.PythonLanguage;
4546
import com.oracle.graal.python.builtins.Builtin;
4647
import com.oracle.graal.python.builtins.CoreFunctions;
4748
import com.oracle.graal.python.builtins.PythonBuiltins;
4849
import com.oracle.graal.python.builtins.objects.PNone;
4950
import com.oracle.graal.python.builtins.objects.function.PKeyword;
51+
import com.oracle.graal.python.nodes.PNodeWithGlobalState;
52+
import com.oracle.graal.python.nodes.PNodeWithGlobalState.DefaultContextManager;
5053
import com.oracle.graal.python.nodes.call.CallNode;
5154
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
5255
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
5356
import com.oracle.graal.python.nodes.function.builtins.PythonVarargsBuiltinNode;
57+
import com.oracle.graal.python.runtime.PythonContext;
58+
import com.oracle.graal.python.runtime.exception.PException;
5459
import com.oracle.truffle.api.Truffle;
5560
import com.oracle.truffle.api.TruffleLanguage;
61+
import com.oracle.truffle.api.TruffleLanguage.ContextReference;
5662
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
5763
import com.oracle.truffle.api.dsl.NodeFactory;
5864
import com.oracle.truffle.api.dsl.Specialization;
@@ -70,7 +76,10 @@ protected List<? extends NodeFactory<? extends PythonBuiltinBaseNode>> getNodeFa
7076
@GenerateNodeFactory
7177
abstract static class RegisterNode extends PythonVarargsBuiltinNode {
7278
private static class AtExitCallTarget extends RootNode {
73-
@Child CallNode callNode = CallNode.create();
79+
@Child private CallNode callNode = CallNode.create();
80+
81+
private final ContextReference<PythonContext> contextRef = lookupContextReference(PythonLanguage.class);
82+
7483
private Object callable;
7584
private Object[] arguments;
7685
private PKeyword[] keywords;
@@ -83,8 +92,12 @@ protected AtExitCallTarget(TruffleLanguage<?> language, Object callable, Object[
8392
}
8493

8594
@Override
95+
@SuppressWarnings("try")
8696
public Object execute(VirtualFrame frame) {
87-
return callNode.execute(frame, callable, arguments, keywords);
97+
// we deliberately pass 'null' frame here
98+
try (DefaultContextManager cm = PNodeWithGlobalState.transferToContext(contextRef, PException.NO_EXCEPTION)) {
99+
return callNode.execute(null, callable, arguments, keywords);
100+
}
88101
}
89102
}
90103

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BinasciiModuleBuiltins.java

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
package com.oracle.graal.python.builtins.modules;
4242

4343
import static com.oracle.graal.python.builtins.PythonBuiltinClassType.ValueError;
44+
import static com.oracle.graal.python.runtime.exception.PythonErrorType.SystemError;
4445

4546
import java.io.UnsupportedEncodingException;
4647
import java.util.List;
@@ -59,8 +60,8 @@
5960
import com.oracle.graal.python.builtins.objects.ints.PInt;
6061
import com.oracle.graal.python.builtins.objects.memoryview.PMemoryView;
6162
import com.oracle.graal.python.builtins.objects.module.PythonModule;
62-
import com.oracle.graal.python.builtins.objects.type.PythonAbstractClass;
6363
import com.oracle.graal.python.builtins.objects.type.LazyPythonClass;
64+
import com.oracle.graal.python.builtins.objects.type.PythonAbstractClass;
6465
import com.oracle.graal.python.nodes.attributes.ReadAttributeFromObjectNode;
6566
import com.oracle.graal.python.nodes.call.special.LookupAndCallUnaryNode;
6667
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
@@ -70,7 +71,6 @@
7071
import com.oracle.graal.python.nodes.util.CastToIntegerFromIntNode;
7172
import com.oracle.graal.python.runtime.PythonCore;
7273
import com.oracle.graal.python.runtime.exception.PException;
73-
import static com.oracle.graal.python.runtime.exception.PythonErrorType.SystemError;
7474
import com.oracle.truffle.api.CompilerDirectives;
7575
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
7676
import com.oracle.truffle.api.dsl.Cached;
@@ -79,6 +79,7 @@
7979
import com.oracle.truffle.api.dsl.NodeFactory;
8080
import com.oracle.truffle.api.dsl.Specialization;
8181
import com.oracle.truffle.api.dsl.TypeSystemReference;
82+
import com.oracle.truffle.api.frame.VirtualFrame;
8283
import com.oracle.truffle.api.profiles.ConditionProfile;
8384
import com.sun.org.apache.xerces.internal.impl.dv.util.Base64;
8485

@@ -111,9 +112,9 @@ PBytes doString(String data) {
111112
}
112113

113114
@Specialization
114-
PBytes doBytesLike(PIBytesLike data,
115+
PBytes doBytesLike(VirtualFrame frame, PIBytesLike data,
115116
@Cached("create()") BytesNodes.ToBytesNode toBytesNode) {
116-
return factory().createBytes(b64decode(toBytesNode.execute(data)));
117+
return factory().createBytes(b64decode(toBytesNode.execute(frame, data)));
117118
}
118119

119120
@TruffleBoundary
@@ -235,8 +236,8 @@ PBytes b2aBytesLike(PIBytesLike data, PInt newline) {
235236
}
236237

237238
@Specialization
238-
PBytes b2aBytesLike(PIBytesLike data, Object newline) {
239-
return (PBytes) getRecursiveNode().execute(data, getCastToIntNode().execute(newline));
239+
PBytes b2aBytesLike(VirtualFrame frame, PIBytesLike data, Object newline) {
240+
return (PBytes) getRecursiveNode().execute(frame, data, getCastToIntNode().execute(newline));
240241
}
241242

242243
@Specialization(guards = "isNoValue(newline)")
@@ -255,38 +256,38 @@ PBytes b2aArray(PArray data, PInt newline) {
255256
}
256257

257258
@Specialization
258-
PBytes b2aArray(PArray data, Object newline) {
259-
return (PBytes) getRecursiveNode().execute(data, getCastToIntNode().execute(newline));
259+
PBytes b2aArray(VirtualFrame frame, PArray data, Object newline) {
260+
return (PBytes) getRecursiveNode().execute(frame, data, getCastToIntNode().execute(newline));
260261
}
261262

262263
@Specialization(guards = "isNoValue(newline)")
263-
PBytes b2aMmeory(PMemoryView data, @SuppressWarnings("unused") PNone newline,
264+
PBytes b2aMmeory(VirtualFrame frame, PMemoryView data, @SuppressWarnings("unused") PNone newline,
264265
@Cached("create(TOBYTES)") LookupAndCallUnaryNode toBytesNode,
265266
@Cached("createBinaryProfile()") ConditionProfile isBytesProfile) {
266-
return b2aMemory(data, 1, toBytesNode, isBytesProfile);
267+
return b2aMemory(frame, data, 1, toBytesNode, isBytesProfile);
267268
}
268269

269270
@Specialization
270-
PBytes b2aMemory(PMemoryView data, long newline,
271+
PBytes b2aMemory(VirtualFrame frame, PMemoryView data, long newline,
271272
@Cached("create(TOBYTES)") LookupAndCallUnaryNode toBytesNode,
272273
@Cached("createBinaryProfile()") ConditionProfile isBytesProfile) {
273-
Object bytesObj = toBytesNode.executeObject(data);
274+
Object bytesObj = toBytesNode.executeObject(frame, data);
274275
if (isBytesProfile.profile(bytesObj instanceof PBytes)) {
275276
return b2aBytesLike((PBytes) bytesObj, newline);
276277
}
277278
throw raise(SystemError, "could not get bytes of memoryview");
278279
}
279280

280281
@Specialization
281-
PBytes b2aMmeory(PMemoryView data, PInt newline,
282+
PBytes b2aMmeory(VirtualFrame frame, PMemoryView data, PInt newline,
282283
@Cached("create(TOBYTES)") LookupAndCallUnaryNode toBytesNode,
283284
@Cached("createBinaryProfile()") ConditionProfile isBytesProfile) {
284-
return b2aMemory(data, newline.isZero() ? 0 : 1, toBytesNode, isBytesProfile);
285+
return b2aMemory(frame, data, newline.isZero() ? 0 : 1, toBytesNode, isBytesProfile);
285286
}
286287

287288
@Specialization
288-
PBytes b2aMmeory(PMemoryView data, Object newline) {
289-
return (PBytes) getRecursiveNode().execute(data, getCastToIntNode().execute(newline));
289+
PBytes b2aMmeory(VirtualFrame frame, PMemoryView data, Object newline) {
290+
return (PBytes) getRecursiveNode().execute(frame, data, getCastToIntNode().execute(newline));
290291
}
291292

292293
@Fallback

0 commit comments

Comments
 (0)