Skip to content

Commit 9e7f957

Browse files
committed
Add _PyTraceback_Add
1 parent d8a3dab commit 9e7f957

File tree

3 files changed

+32
-8
lines changed

3 files changed

+32
-8
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,8 @@ UPCALL_ID(PyTraceBack_Here);
4747
int PyTraceBack_Here(PyFrameObject *frame) {
4848
return UPCALL_CEXT_I(_jls_PyTraceBack_Here, native_to_java((PyObject*)frame));
4949
}
50+
51+
UPCALL_ID(_PyTraceback_Add)
52+
void _PyTraceback_Add(const char *funcname, const char *filename, int lineno) {
53+
return UPCALL_CEXT_VOID(_jls__PyTraceback_Add, polyglot_from_string(funcname, SRC_CS), polyglot_from_string(filename, SRC_CS), lineno);
54+
}

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

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
import static com.oracle.graal.python.nodes.SpecialAttributeNames.__NAME__;
5151
import static com.oracle.graal.python.nodes.SpecialMethodNames.__NEW__;
5252
import static com.oracle.graal.python.runtime.exception.PythonErrorType.OverflowError;
53+
import static com.oracle.graal.python.util.PythonUtils.EMPTY_BYTE_ARRAY;
54+
import static com.oracle.graal.python.util.PythonUtils.EMPTY_OBJECT_ARRAY;
5355

5456
import java.io.PrintWriter;
5557
import java.math.BigInteger;
@@ -165,6 +167,7 @@
165167
import com.oracle.graal.python.builtins.objects.cext.common.CExtContext.Store;
166168
import com.oracle.graal.python.builtins.objects.cext.common.CExtParseArgumentsNode;
167169
import com.oracle.graal.python.builtins.objects.cext.common.CExtParseArgumentsNode.SplitFormatStringNode;
170+
import com.oracle.graal.python.builtins.objects.code.CodeNodes;
168171
import com.oracle.graal.python.builtins.objects.code.CodeNodes.GetCodeCallTargetNode;
169172
import com.oracle.graal.python.builtins.objects.code.CodeNodes.GetCodeSignatureNode;
170173
import com.oracle.graal.python.builtins.objects.code.PCode;
@@ -1488,6 +1491,22 @@ int tbHere(PFrame frame,
14881491
}
14891492
}
14901493

1494+
@Builtin(name = "_PyTraceback_Add", minNumOfPositionalArgs = 1)
1495+
@GenerateNodeFactory
1496+
abstract static class PyTracebackAdd extends PythonTernaryBuiltinNode {
1497+
@Specialization
1498+
Object tbHere(String funcname, String filename, int lineno,
1499+
@Cached CodeNodes.CreateCodeNode createCodeNode,
1500+
@Cached PyTraceBackHereNode pyTraceBackHereNode) {
1501+
PCode code = createCodeNode.execute(null, 0, 0, 0, 0, 0, 0,
1502+
EMPTY_BYTE_ARRAY, EMPTY_OBJECT_ARRAY, EMPTY_OBJECT_ARRAY, EMPTY_OBJECT_ARRAY, EMPTY_OBJECT_ARRAY, EMPTY_OBJECT_ARRAY,
1503+
filename, funcname, lineno, EMPTY_BYTE_ARRAY);
1504+
PFrame frame = factory().createPFrame(null, code, factory().createDict(), factory().createDict());
1505+
pyTraceBackHereNode.execute(null, frame);
1506+
return PNone.NONE;
1507+
}
1508+
}
1509+
14911510
@Builtin(name = "PyTruffle_Set_SulongType", minNumOfPositionalArgs = 2)
14921511
@GenerateNodeFactory
14931512
abstract static class PyTruffle_Set_SulongType extends NativeBuiltin {
@@ -2879,7 +2898,7 @@ abstract static class CastArgsNode extends Node {
28792898
@SuppressWarnings("unused")
28802899
static Object[] doNull(VirtualFrame frame, Object argsObj,
28812900
@Shared("lib") @CachedLibrary(limit = "3") InteropLibrary lib) {
2882-
return PythonUtils.EMPTY_OBJECT_ARRAY;
2901+
return EMPTY_OBJECT_ARRAY;
28832902
}
28842903

28852904
@Specialization(guards = "!lib.isNull(argsObj)")
@@ -4068,14 +4087,14 @@ static GetSetDescriptor createGetSet(String name, Object clazz, Object getter, O
40684087
PBuiltinFunction get = null;
40694088
if (!interopLibrary.isNull(getter)) {
40704089
RootCallTarget getterCT = getterCallTarget(name, language);
4071-
get = factory.createGetSetBuiltinFunction(name, cls, PythonUtils.EMPTY_OBJECT_ARRAY, ExternalFunctionNodes.createKwDefaults(getter, closure), getterCT);
4090+
get = factory.createGetSetBuiltinFunction(name, cls, EMPTY_OBJECT_ARRAY, ExternalFunctionNodes.createKwDefaults(getter, closure), getterCT);
40724091
}
40734092

40744093
PBuiltinFunction set = null;
40754094
boolean hasSetter = !interopLibrary.isNull(setter);
40764095
if (hasSetter) {
40774096
RootCallTarget setterCT = setterCallTarget(name, language);
4078-
set = factory.createGetSetBuiltinFunction(name, cls, PythonUtils.EMPTY_OBJECT_ARRAY, ExternalFunctionNodes.createKwDefaults(setter, closure), setterCT);
4097+
set = factory.createGetSetBuiltinFunction(name, cls, EMPTY_OBJECT_ARRAY, ExternalFunctionNodes.createKwDefaults(setter, closure), setterCT);
40794098
}
40804099

40814100
// create get-set descriptor
@@ -4350,7 +4369,7 @@ Object doGeneric(Object clsPtr,
43504369
Object realSizeObj = readRealSizeNode.execute(cls, StructSequence.N_FIELDS);
43514370
Object res;
43524371
if (realSizeObj == PNone.NO_VALUE) {
4353-
PRaiseNativeNode.raiseNative(null, SystemError, ErrorMessages.BAD_ARG_TO_INTERNAL_FUNC, PythonUtils.EMPTY_OBJECT_ARRAY, getRaiseNode(), transformExceptionToNativeNode);
4372+
PRaiseNativeNode.raiseNative(null, SystemError, ErrorMessages.BAD_ARG_TO_INTERNAL_FUNC, EMPTY_OBJECT_ARRAY, getRaiseNode(), transformExceptionToNativeNode);
43544373
res = getNativeNullNode.execute();
43554374
} else {
43564375
int realSize = castToIntNode.execute(realSizeObj);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/code/CodeNodes.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,13 @@ private static PCode createCode(PythonLanguage language, PythonContext context,
119119

120120
RootCallTarget ct;
121121
if (codedata.length == 0) {
122-
ct = language.createCachedCallTarget(l -> new BadOPCodeNode(l, name), BadOPCodeNode.class, name);
122+
ct = language.createCachedCallTarget(l -> new BadOPCodeNode(l, name), BadOPCodeNode.class, filename, name);
123123
} else {
124124
RootNode rootNode = context.getSerializer().deserialize(context, codedata, toStringArray(cellvars), toStringArray(freevars));
125125
ct = PythonUtils.getOrCreateCallTarget(rootNode);
126-
if (filename != null) {
127-
context.setCodeFilename(ct, filename);
128-
}
126+
}
127+
if (filename != null) {
128+
context.setCodeFilename(ct, filename);
129129
}
130130
PythonObjectFactory factory = context.factory();
131131
return factory.createCode(ct, ((PRootNode) ct.getRootNode()).getSignature(), nlocals, stacksize, flags, constants, names, varnames, freevars, cellvars, filename, name,

0 commit comments

Comments
 (0)