Skip to content

Commit f9f4f80

Browse files
committed
fix most blacklisted method warnings
1 parent 93f60c9 commit f9f4f80

File tree

85 files changed

+478
-235
lines changed

Some content is hidden

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

85 files changed

+478
-235
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/PythonLanguage.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,7 @@ protected Object getLanguageView(PythonContext context, Object value) {
339339
return new ForeignLanguageView(value);
340340
}
341341
} catch (UnsupportedMessageException e) {
342+
CompilerDirectives.transferToInterpreterAndInvalidate();
342343
throw new IllegalStateException(e);
343344
}
344345
}

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
import static com.oracle.graal.python.nodes.SpecialMethodNames.__TRUNC__;
6969
import static com.oracle.graal.python.runtime.exception.PythonErrorType.NotImplementedError;
7070
import static com.oracle.graal.python.runtime.exception.PythonErrorType.OverflowError;
71+
import static com.oracle.graal.python.runtime.exception.PythonErrorType.RuntimeError;
7172
import static com.oracle.graal.python.runtime.exception.PythonErrorType.SystemError;
7273
import static com.oracle.graal.python.runtime.exception.PythonErrorType.TypeError;
7374
import static com.oracle.graal.python.runtime.exception.PythonErrorType.ValueError;
@@ -1181,6 +1182,7 @@ private Object createInt(LazyPythonClass cls, Object value) {
11811182
return factory().createInt(cls, ((PInt) value).getValue());
11821183
}
11831184
}
1185+
CompilerDirectives.transferToInterpreterAndInvalidate();
11841186
throw new IllegalStateException("Unexpected type");
11851187
}
11861188

@@ -1479,7 +1481,7 @@ Object createInt(LazyPythonClass cls, PythonNativeVoidPtr arg, @SuppressWarnings
14791481
if (isPrimitiveInt(cls)) {
14801482
return arg;
14811483
} else {
1482-
CompilerDirectives.transferToInterpreter();
1484+
CompilerDirectives.transferToInterpreterAndInvalidate();
14831485
throw new IllegalStateException("cannot wrap void ptr in int subclass");
14841486
}
14851487
}
@@ -1683,6 +1685,7 @@ private static PythonNativeClass findFirstNativeBaseClass(PythonAbstractClass[]
16831685
return PythonNativeClass.cast(cls);
16841686
}
16851687
}
1688+
CompilerDirectives.transferToInterpreterAndInvalidate();
16861689
throw new IllegalStateException("class needs native allocation but has not native base class");
16871690
}
16881691

@@ -2221,7 +2224,7 @@ private String getModuleNameFromGlobals(PythonObject globals, HashingStorageLibr
22212224
} else if (globals instanceof PDict) {
22222225
nameAttr = hlib.getItem(((PDict) globals).getDictStorage(), __NAME__);
22232226
} else {
2224-
CompilerDirectives.transferToInterpreter();
2227+
CompilerDirectives.transferToInterpreterAndInvalidate();
22252228
throw new IllegalStateException("invalid globals object");
22262229
}
22272230
return ensureCastToStringNode().execute(nameAttr);
@@ -2817,7 +2820,7 @@ Object method(LazyPythonClass cls, Object self, PBuiltinFunction func) {
28172820
public abstract static class FrameTypeNode extends PythonBuiltinNode {
28182821
@Specialization
28192822
Object call() {
2820-
throw new RuntimeException("cannot call constructor of frame type");
2823+
throw raise(RuntimeError, "cannot call constructor of frame type");
28212824
}
28222825
}
28232826

@@ -2826,7 +2829,7 @@ Object call() {
28262829
public abstract static class TracebackTypeNode extends PythonBuiltinNode {
28272830
@Specialization
28282831
Object call() {
2829-
throw new RuntimeException("cannot call constructor of traceback type");
2832+
throw raise(RuntimeError, "cannot call constructor of traceback type");
28302833
}
28312834
}
28322835

@@ -2927,7 +2930,7 @@ private static byte[] toBytes(String data) {
29272930
public abstract static class CellTypeNode extends PythonBuiltinNode {
29282931
@Specialization
29292932
Object call() {
2930-
throw new RuntimeException("cannot call constructor of cell type");
2933+
throw raise(RuntimeError, "cannot call constructor of cell type");
29312934
}
29322935
}
29332936

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ boolean doGeneric(Object object,
398398
* Added temporarily to skip translation/execution errors in unit testing
399399
*/
400400

401-
if (object.equals(GraalPythonTranslationErrorNode.MESSAGE)) {
401+
if (GraalPythonTranslationErrorNode.MESSAGE.equals(object)) {
402402
return true;
403403
}
404404

@@ -603,7 +603,7 @@ private void setBuiltinsInGlobals(VirtualFrame frame, PDict globals, HashingColl
603603
try {
604604
lib.setDict(builtins, builtinsDict);
605605
} catch (UnsupportedMessageException e) {
606-
CompilerDirectives.transferToInterpreter();
606+
CompilerDirectives.transferToInterpreterAndInvalidate();
607607
throw new IllegalStateException(e);
608608
}
609609
}
@@ -1444,7 +1444,7 @@ public int ord(VirtualFrame frame, PIBytesLike chr,
14441444
} else if (element instanceof Byte) {
14451445
return (byte) element;
14461446
}
1447-
CompilerDirectives.transferToInterpreter();
1447+
CompilerDirectives.transferToInterpreterAndInvalidate();
14481448
throw new IllegalStateException("got a bytes-like with non-byte elements");
14491449
}
14501450
}
@@ -1860,7 +1860,7 @@ public Object globals(VirtualFrame frame,
18601860
try {
18611861
lib.setDict(globals, dict);
18621862
} catch (UnsupportedMessageException e) {
1863-
CompilerDirectives.transferToInterpreter();
1863+
CompilerDirectives.transferToInterpreterAndInvalidate();
18641864
throw new IllegalStateException(e);
18651865
}
18661866
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@
4242

4343
import com.oracle.graal.python.PythonLanguage;
4444
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
45+
import com.oracle.graal.python.builtins.modules.ExternalFunctionNodesFactory.ExternalFunctionNodeGen;
4546
import com.oracle.graal.python.builtins.modules.PythonCextBuiltins.CheckFunctionResultNode;
4647
import com.oracle.graal.python.builtins.modules.PythonCextBuiltins.TrufflePInt_AsPrimitive;
4748
import com.oracle.graal.python.builtins.modules.PythonCextBuiltinsFactory.TrufflePInt_AsPrimitiveFactory;
48-
import com.oracle.graal.python.builtins.modules.ExternalFunctionNodesFactory.ExternalFunctionNodeGen;
4949
import com.oracle.graal.python.builtins.objects.PNone;
5050
import com.oracle.graal.python.builtins.objects.cext.CExtNodes;
5151
import com.oracle.graal.python.builtins.objects.cext.CExtNodes.ConvertArgsToSulongNode;
@@ -141,10 +141,10 @@ Object doIt(VirtualFrame frame,
141141
try {
142142
return fromNative(asPythonObjectNode.execute(checkResultNode.execute(name, lib.execute(callable, arguments))));
143143
} catch (UnsupportedTypeException | UnsupportedMessageException e) {
144-
CompilerDirectives.transferToInterpreter();
144+
CompilerDirectives.transferToInterpreterAndInvalidate();
145145
throw raiseNode.raise(PythonBuiltinClassType.TypeError, "Calling native function %s failed: %m", name, e);
146146
} catch (ArityException e) {
147-
CompilerDirectives.transferToInterpreter();
147+
CompilerDirectives.transferToInterpreterAndInvalidate();
148148
throw raiseNode.raise(PythonBuiltinClassType.TypeError, "Calling native function %s expected %d arguments but got %d.", name, e.getExpectedArity(), e.getActualArity());
149149
} finally {
150150
// special case after calling a C function: transfer caught exception back to frame

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

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -306,27 +306,27 @@ public double copySignDD(double magnitude, double sign) {
306306

307307
@Specialization
308308
public double copySignPIL(PInt magnitude, long sign) {
309-
return Math.copySign(magnitude.getValue().doubleValue(), sign);
309+
return Math.copySign(magnitude.doubleValue(), sign);
310310
}
311311

312312
@Specialization
313313
public double copySignPID(PInt magnitude, double sign) {
314-
return Math.copySign(magnitude.getValue().doubleValue(), sign);
314+
return Math.copySign(magnitude.doubleValue(), sign);
315315
}
316316

317317
@Specialization
318318
public double copySignLPI(long magnitude, PInt sign) {
319-
return Math.copySign(magnitude, sign.getValue().doubleValue());
319+
return Math.copySign(magnitude, sign.doubleValue());
320320
}
321321

322322
@Specialization
323323
public double copySignDPI(double magnitude, PInt sign) {
324-
return Math.copySign(magnitude, sign.getValue().doubleValue());
324+
return Math.copySign(magnitude, sign.doubleValue());
325325
}
326326

327327
@Specialization
328328
public double copySignPIPI(PInt magnitude, PInt sign) {
329-
return Math.copySign(magnitude.getValue().doubleValue(), sign.getValue().doubleValue());
329+
return Math.copySign(magnitude.doubleValue(), sign.doubleValue());
330330
}
331331

332332
@Specialization(guards = "!isNumber(magnitude) || !isNumber(sign)")
@@ -499,7 +499,7 @@ protected boolean isInteger(double value) {
499499
}
500500

501501
protected boolean isNegative(PInt value) {
502-
return value.getValue().compareTo(BigInteger.ZERO) < 0;
502+
return value.isNegative();
503503
}
504504

505505
protected boolean isNegative(double value) {
@@ -511,7 +511,7 @@ protected boolean isOvf(double value) {
511511
}
512512

513513
protected boolean isOvf(PInt value) {
514-
return value.getValue().compareTo(BigInteger.valueOf(Long.MAX_VALUE)) > 0;
514+
return value.compareTo(Long.MAX_VALUE) > 0;
515515
}
516516

517517
protected static FactorialNode create() {
@@ -624,10 +624,9 @@ public double fmodDL(double left, long right,
624624
}
625625

626626
@Specialization
627-
@TruffleBoundary
628627
public double fmodDPI(double left, PInt right) {
629628
raiseMathDomainError(Double.isInfinite(left));
630-
double rvalue = right.getValue().doubleValue();
629+
double rvalue = right.doubleValue();
631630
raiseMathDomainError(rvalue == 0);
632631
return left % rvalue;
633632
}
@@ -649,32 +648,30 @@ public double fmodLD(long left, double right,
649648
@Specialization
650649
@TruffleBoundary
651650
public double fmodLPI(long left, PInt right) {
652-
double rvalue = right.getValue().doubleValue();
651+
double rvalue = right.doubleValue();
653652
raiseMathDomainError(rvalue == 0);
654653
return left % rvalue;
655654
}
656655

657656
@Specialization
658657
public double fmodPIPI(PInt left, PInt right) {
659-
double rvalue = right.getValue().doubleValue();
658+
double rvalue = right.doubleValue();
660659
raiseMathDomainError(rvalue == 0);
661-
double lvalue = left.getValue().doubleValue();
660+
double lvalue = left.doubleValue();
662661
return lvalue % rvalue;
663662
}
664663

665664
@Specialization
666-
@TruffleBoundary
667665
public double fmodPIL(PInt left, long right) {
668666
raiseMathDomainError(right == 0);
669-
double lvalue = left.getValue().doubleValue();
667+
double lvalue = left.doubleValue();
670668
return lvalue % right;
671669
}
672670

673671
@Specialization
674-
@TruffleBoundary
675672
public double fmodPID(PInt left, double right) {
676673
raiseMathDomainError(right == 0);
677-
double lvalue = left.getValue().doubleValue();
674+
double lvalue = left.doubleValue();
678675
return lvalue % right;
679676
}
680677

@@ -969,9 +966,8 @@ public double ldexpLPI(long mantissa, PInt exp) {
969966
}
970967

971968
@Specialization
972-
@TruffleBoundary
973969
public double ldexpPIPI(PInt mantissa, PInt exp) {
974-
double dm = mantissa.getValue().doubleValue();
970+
double dm = mantissa.doubleValue();
975971
return exceptInfinity(Math.scalb(dm, makeInt(exp)), dm);
976972
}
977973

@@ -982,7 +978,7 @@ public double ldexpPID(@SuppressWarnings("unused") PInt mantissa, @SuppressWarni
982978

983979
@Specialization
984980
public double ldexpPIL(PInt mantissa, long exp) {
985-
double dm = mantissa.getValue().doubleValue();
981+
double dm = mantissa.doubleValue();
986982
return exceptInfinity(Math.scalb(dm, makeInt(exp)), dm);
987983
}
988984

@@ -1196,17 +1192,22 @@ long gcd(long x, long y) {
11961192

11971193
@Specialization
11981194
PInt gcd(long x, PInt y) {
1199-
return factory().createInt(BigInteger.valueOf(x).gcd(y.getValue()));
1195+
return factory().createInt(op(PInt.longToBigInteger(x), y.getValue()));
12001196
}
12011197

12021198
@Specialization
12031199
PInt gcd(PInt x, long y) {
1204-
return factory().createInt(x.getValue().gcd(BigInteger.valueOf(y)));
1200+
return factory().createInt(op(x.getValue(), PInt.longToBigInteger(y)));
1201+
}
1202+
1203+
@TruffleBoundary
1204+
private static BigInteger op(BigInteger x, BigInteger y) {
1205+
return x.gcd(y);
12051206
}
12061207

12071208
@Specialization
12081209
PInt gcd(PInt x, PInt y) {
1209-
return factory().createInt(x.getValue().gcd(y.getValue()));
1210+
return factory().createInt(op(x.getValue(), y.getValue()));
12101211
}
12111212

12121213
@Specialization
@@ -1757,9 +1758,8 @@ public double fabs(long value) {
17571758
}
17581759

17591760
@Specialization
1760-
@TruffleBoundary
17611761
public PInt fabs(PInt value) {
1762-
BigInteger xabs = value.getValue().abs();
1762+
BigInteger xabs = value.abs();
17631763
return factory().createInt(xabs);
17641764
}
17651765

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import com.oracle.graal.python.builtins.CoreFunctions;
4949
import com.oracle.graal.python.builtins.PythonBuiltins;
5050
import com.oracle.graal.python.builtins.objects.PNone;
51+
import com.oracle.graal.python.builtins.objects.common.SequenceNodes;
5152
import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes;
5253
import com.oracle.graal.python.builtins.objects.dict.PDict;
5354
import com.oracle.graal.python.builtins.objects.ints.PInt;
@@ -199,8 +200,9 @@ public Object doDict(PDict dict, Object item) {
199200

200201
@Specialization
201202
public Object doSequence(VirtualFrame frame, PSequence value, Object index,
202-
@Cached("create()") SequenceStorageNodes.GetItemNode getItemNode) {
203-
return getItemNode.execute(frame, value.getSequenceStorage(), index);
203+
@Cached SequenceNodes.GetSequenceStorageNode getStorage,
204+
@Cached SequenceStorageNodes.GetItemNode getItemNode) {
205+
return getItemNode.execute(frame, getStorage.execute(value), index);
204206
}
205207

206208
@Specialization

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ static InteropLibrary getInterop() {
359359
@GenerateNodeFactory
360360
public abstract static class ReadNode extends PythonBuiltinNode {
361361
@Specialization
362+
@TruffleBoundary
362363
Object read(Object receiver, Object key) {
363364
try {
364365
if (key instanceof String) {
@@ -378,6 +379,7 @@ Object read(Object receiver, Object key) {
378379
@GenerateNodeFactory
379380
public abstract static class WriteNode extends PythonBuiltinNode {
380381
@Specialization
382+
@TruffleBoundary
381383
Object write(Object receiver, Object key, Object value) {
382384
try {
383385
if (key instanceof String) {
@@ -398,6 +400,7 @@ Object write(Object receiver, Object key, Object value) {
398400
@GenerateNodeFactory
399401
public abstract static class removeNode extends PythonBuiltinNode {
400402
@Specialization
403+
@TruffleBoundary
401404
Object remove(Object receiver, Object key) {
402405
try {
403406
if (key instanceof String) {

0 commit comments

Comments
 (0)