Skip to content

Commit da977c5

Browse files
committed
Make tb_next writable
1 parent 797068c commit da977c5

File tree

1 file changed

+33
-6
lines changed
  • graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/traceback

1 file changed

+33
-6
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/traceback/TracebackBuiltins.java

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
*/
2626
package com.oracle.graal.python.builtins.objects.traceback;
2727

28+
import static com.oracle.graal.python.builtins.PythonBuiltinClassType.TypeError;
2829
import static com.oracle.graal.python.builtins.objects.traceback.PTraceback.TB_FRAME;
2930
import static com.oracle.graal.python.builtins.objects.traceback.PTraceback.TB_LASTI;
3031
import static com.oracle.graal.python.builtins.objects.traceback.PTraceback.TB_LINENO;
@@ -45,6 +46,7 @@
4546
import com.oracle.graal.python.nodes.frame.ReadCallerFrameNode;
4647
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
4748
import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
49+
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode;
4850
import com.oracle.graal.python.runtime.exception.PException;
4951
import com.oracle.graal.python.runtime.object.PythonObjectFactory;
5052
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
@@ -257,14 +259,39 @@ protected static boolean isMaterialized(PFrame.Reference frameInfo) {
257259
}
258260
}
259261

260-
@Builtin(name = TB_NEXT, minNumOfPositionalArgs = 1, isGetter = true)
262+
@Builtin(name = TB_NEXT, minNumOfPositionalArgs = 1, maxNumOfPositionalArgs = 2, isGetter = true, isSetter = true)
261263
@GenerateNodeFactory
262-
public abstract static class GetTracebackNextNode extends PythonBuiltinNode {
263-
@Specialization
264-
Object get(PTraceback tb,
264+
public abstract static class GetTracebackNextNode extends PythonBinaryBuiltinNode {
265+
@Specialization(guards = "isNoValue(none)")
266+
Object get(PTraceback self, @SuppressWarnings("unused") PNone none,
265267
@Cached MaterializeTruffleStacktraceNode materializeTruffleStacktraceNode) {
266-
materializeTruffleStacktraceNode.execute(tb);
267-
return (tb.getNext() != null) ? tb.getNext() : PNone.NONE;
268+
materializeTruffleStacktraceNode.execute(self);
269+
return (self.getNext() != null) ? self.getNext() : PNone.NONE;
270+
}
271+
272+
@Specialization(guards = "!isNoValue(next)")
273+
Object set(PTraceback self, PTraceback next,
274+
@Cached MaterializeTruffleStacktraceNode materializeTruffleStacktraceNode) {
275+
// Realize whatever was in the truffle stacktrace, so that we don't overwrite the
276+
// user-set next later
277+
materializeTruffleStacktraceNode.execute(self);
278+
self.setNext(next);
279+
return PNone.NONE;
280+
}
281+
282+
@Specialization(guards = "isNone(next)")
283+
Object clear(PTraceback self, @SuppressWarnings("unused") PNone next,
284+
@Cached MaterializeTruffleStacktraceNode materializeTruffleStacktraceNode) {
285+
// Realize whatever was in the truffle stacktrace, so that we don't overwrite the
286+
// user-set next later
287+
materializeTruffleStacktraceNode.execute(self);
288+
self.setNext(null);
289+
return PNone.NONE;
290+
}
291+
292+
@Specialization(guards = {"!isPNone(next)", "!isPTraceback(next)"})
293+
Object setError(@SuppressWarnings("unused") PTraceback self, Object next) {
294+
throw raise(TypeError, "expected traceback object, got '%p'", next);
268295
}
269296
}
270297

0 commit comments

Comments
 (0)