Skip to content

Commit 01c89d2

Browse files
committed
fix ambigous use of data field in PBaseException
1 parent b52f0ca commit 01c89d2

File tree

5 files changed

+30
-20
lines changed

5 files changed

+30
-20
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/PBaseException.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@
7474

7575
@ExportLibrary(InteropLibrary.class)
7676
public final class PBaseException extends PythonObject {
77+
public static class Data {
78+
79+
}
80+
7781
private static final ErrorMessageFormatter FORMATTER = new ErrorMessageFormatter();
7882

7983
private PTuple args; // can be null for lazily generated message
@@ -91,9 +95,9 @@ public final class PBaseException extends PythonObject {
9195
private boolean suppressContext = false;
9296
// the data instance is used to store additional information for some of the builtin exceptions
9397
// not unlike subclassing
94-
private Object data;
98+
private Data data;
9599

96-
public PBaseException(Object cls, Shape instanceShape, Object data, PTuple args) {
100+
public PBaseException(Object cls, Shape instanceShape, Data data, PTuple args) {
97101
super(cls, instanceShape);
98102
this.data = data;
99103
this.args = args;
@@ -102,7 +106,7 @@ public PBaseException(Object cls, Shape instanceShape, Object data, PTuple args)
102106
this.messageArgs = null;
103107
}
104108

105-
public PBaseException(Object cls, Shape instanceShape, Object data) {
109+
public PBaseException(Object cls, Shape instanceShape, Data data) {
106110
super(cls, instanceShape);
107111
this.data = data;
108112
this.args = null;
@@ -111,7 +115,7 @@ public PBaseException(Object cls, Shape instanceShape, Object data) {
111115
this.messageArgs = null;
112116
}
113117

114-
public PBaseException(Object cls, Shape instanceShape, Object data, String format, Object[] args) {
118+
public PBaseException(Object cls, Shape instanceShape, Data data, String format, Object[] args) {
115119
super(cls, instanceShape);
116120
this.data = data;
117121
this.args = null;
@@ -120,11 +124,11 @@ public PBaseException(Object cls, Shape instanceShape, Object data, String forma
120124
this.messageArgs = args;
121125
}
122126

123-
public Object getData() {
127+
public Data getData() {
124128
return data;
125129
}
126130

127-
public void setData(Object data) {
131+
public void setData(Data data) {
128132
this.data = data;
129133
}
130134

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/SystemExitBuiltins.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ protected List<? extends NodeFactory<? extends PythonBuiltinBaseNode>> getNodeFa
6767
}
6868

6969
@CompilerDirectives.ValueType
70-
public static final class SystemExitData {
70+
public static final class SystemExitData extends PBaseException.Data {
7171
private Object code;
7272

7373
private SystemExitData() {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyTraceBackPrintNode.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@
8181
import static com.oracle.graal.python.util.PythonUtils.NEW_LINE;
8282

8383
/**
84-
* Equivalent of {@code PyTraceBack_Print} from CPython.
85-
* the node contains also a number of utility static methods
84+
* Equivalent of {@code PyTraceBack_Print} from CPython. the node contains also a number of utility
85+
* static methods
8686
*/
8787
public abstract class PyTraceBackPrintNode extends PNodeWithContext {
8888
static final int TRACEBACK_LIMIT = 1000;

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/PRaiseNode.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public final PException execute(Node raisingNode, PythonBuiltinClassType type, O
6868
return execute(raisingNode, type, null, cause, format, arguments);
6969
}
7070

71-
public abstract PException execute(Node raisingNode, PythonBuiltinClassType type, Object data, Object cause, Object format, Object[] arguments);
71+
public abstract PException execute(Node raisingNode, PythonBuiltinClassType type, PBaseException.Data data, Object cause, Object format, Object[] arguments);
7272

7373
public final PException raise(PythonBuiltinClassType type) {
7474
throw execute(this, type, null, PNone.NO_VALUE, PNone.NO_VALUE, PythonUtils.EMPTY_OBJECT_ARRAY);
@@ -86,7 +86,7 @@ public final PException raise(PythonBuiltinClassType type, Object... arguments)
8686
throw execute(this, type, null, PNone.NO_VALUE, PNone.NO_VALUE, arguments);
8787
}
8888

89-
public final PException raiseWithData(PythonBuiltinClassType type, Object data, Object... arguments) {
89+
public final PException raiseWithData(PythonBuiltinClassType type, PBaseException.Data data, Object... arguments) {
9090
throw execute(this, type, data, PNone.NO_VALUE, PNone.NO_VALUE, arguments);
9191
}
9292

@@ -168,7 +168,7 @@ public static PException raise(Node raisingNode, PBaseException exc, boolean wit
168168
}
169169

170170
@Specialization(guards = {"isNoValue(cause)", "isNoValue(format)", "arguments.length == 0", "exceptionType == cachedType"}, limit = "8")
171-
static PException doPythonBuiltinTypeCached(Node raisingNode, @SuppressWarnings("unused") PythonBuiltinClassType exceptionType, Object data, @SuppressWarnings("unused") PNone cause,
171+
static PException doPythonBuiltinTypeCached(Node raisingNode, @SuppressWarnings("unused") PythonBuiltinClassType exceptionType, PBaseException.Data data, @SuppressWarnings("unused") PNone cause,
172172
@SuppressWarnings("unused") PNone format,
173173
@SuppressWarnings("unused") Object[] arguments,
174174
@Cached("exceptionType") PythonBuiltinClassType cachedType,
@@ -177,27 +177,29 @@ static PException doPythonBuiltinTypeCached(Node raisingNode, @SuppressWarnings(
177177
}
178178

179179
@Specialization(guards = {"isNoValue(cause)", "isNoValue(format)", "arguments.length == 0"}, replaces = "doPythonBuiltinTypeCached")
180-
static PException doPythonBuiltinType(Node raisingNode, PythonBuiltinClassType exceptionType, Object data, @SuppressWarnings("unused") PNone cause, @SuppressWarnings("unused") PNone format,
180+
static PException doPythonBuiltinType(Node raisingNode, PythonBuiltinClassType exceptionType, PBaseException.Data data, @SuppressWarnings("unused") PNone cause,
181+
@SuppressWarnings("unused") PNone format,
181182
@SuppressWarnings("unused") Object[] arguments,
182183
@Shared("factory") @Cached PythonObjectFactory factory) {
183184
throw raiseExceptionObject(raisingNode, factory.createBaseException(exceptionType, data));
184185
}
185186

186187
@Specialization(guards = {"isNoValue(cause)", "isNoValue(format)", "arguments.length > 0"})
187-
static PException doBuiltinType(Node raisingNode, PythonBuiltinClassType type, Object data, @SuppressWarnings("unused") PNone cause, @SuppressWarnings("unused") PNone format, Object[] arguments,
188+
static PException doBuiltinType(Node raisingNode, PythonBuiltinClassType type, PBaseException.Data data, @SuppressWarnings("unused") PNone cause, @SuppressWarnings("unused") PNone format,
189+
Object[] arguments,
188190
@Shared("factory") @Cached PythonObjectFactory factory) {
189191
throw raiseExceptionObject(raisingNode, factory.createBaseException(type, data, factory.createTuple(arguments)));
190192
}
191193

192194
@Specialization(guards = {"isNoValue(cause)"})
193-
static PException doBuiltinType(Node raisingNode, PythonBuiltinClassType type, Object data, @SuppressWarnings("unused") PNone cause, String format, Object[] arguments,
195+
static PException doBuiltinType(Node raisingNode, PythonBuiltinClassType type, PBaseException.Data data, @SuppressWarnings("unused") PNone cause, String format, Object[] arguments,
194196
@Shared("factory") @Cached PythonObjectFactory factory) {
195197
assert format != null;
196198
throw raiseExceptionObject(raisingNode, factory.createBaseException(type, data, format, arguments));
197199
}
198200

199201
@Specialization(guards = {"!isNoValue(cause)"})
200-
static PException doBuiltinTypeWithCause(Node raisingNode, PythonBuiltinClassType type, Object data, PBaseException cause, String format, Object[] arguments,
202+
static PException doBuiltinTypeWithCause(Node raisingNode, PythonBuiltinClassType type, PBaseException.Data data, PBaseException cause, String format, Object[] arguments,
201203
@Shared("factory") @Cached PythonObjectFactory factory) {
202204
assert format != null;
203205
PBaseException baseException = factory.createBaseException(type, data, format, arguments);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/object/PythonObjectFactory.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -860,24 +860,28 @@ public final PTraceback createTraceback(LazyTraceback tb) {
860860
return trace(new PTraceback(getLanguage(), tb));
861861
}
862862

863-
public final PBaseException createBaseException(Object cls, Object data, PTuple args) {
863+
public final PBaseException createBaseException(Object cls, PTuple args) {
864+
return createBaseException(cls, null, args);
865+
}
866+
867+
public final PBaseException createBaseException(Object cls, PBaseException.Data data, PTuple args) {
864868
return trace(new PBaseException(cls, getShape(cls), data, args));
865869
}
866870

867871
public final PBaseException createBaseException(Object cls, String format, Object[] args) {
868872
return createBaseException(cls, null, format, args);
869873
}
870874

871-
public final PBaseException createBaseException(Object cls, Object data, String format, Object[] args) {
875+
public final PBaseException createBaseException(Object cls, PBaseException.Data data, String format, Object[] args) {
872876
assert format != null;
873877
return trace(new PBaseException(cls, getShape(cls), data, format, args));
874878
}
875879

876880
public final PBaseException createBaseException(Object cls) {
877-
return createBaseException(cls, null);
881+
return trace(new PBaseException(cls, getShape(cls), null));
878882
}
879883

880-
public final PBaseException createBaseException(Object cls, Object data) {
884+
public final PBaseException createBaseException(Object cls, PBaseException.Data data) {
881885
return trace(new PBaseException(cls, getShape(cls), data));
882886
}
883887

0 commit comments

Comments
 (0)