Skip to content

Commit 989adfd

Browse files
committed
Fix unchecked cast warnings
1 parent a2928c9 commit 989adfd

File tree

3 files changed

+15
-12
lines changed

3 files changed

+15
-12
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/CApiContext.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
import java.util.Objects;
5252
import java.util.logging.Level;
5353

54-
import com.oracle.graal.python.builtins.objects.cext.common.ReferenceStack;
5554
import org.graalvm.collections.EconomicMap;
5655

5756
import com.oracle.graal.python.PythonLanguage;
@@ -68,6 +67,7 @@
6867
import com.oracle.graal.python.builtins.objects.cext.capi.NativeObjectReferenceArrayWrapper.PointerArrayWrapper;
6968
import com.oracle.graal.python.builtins.objects.cext.capi.NativeObjectReferenceArrayWrapper.RefCountArrayWrapper;
7069
import com.oracle.graal.python.builtins.objects.cext.common.CExtContext;
70+
import com.oracle.graal.python.builtins.objects.cext.common.ReferenceStack;
7171
import com.oracle.graal.python.builtins.objects.frame.PFrame;
7272
import com.oracle.graal.python.builtins.objects.function.PArguments;
7373
import com.oracle.graal.python.builtins.objects.function.Signature;
@@ -136,7 +136,7 @@ public final class CApiContext extends CExtContext {
136136
public CApiContext(PythonContext context, Object hpyLibrary) {
137137
super(context, hpyLibrary, CAPIConversionNodeSupplier.INSTANCE);
138138
nativeObjectsQueue = new ReferenceQueue<>();
139-
nativeObjectWrapperList = new ReferenceStack<>(NativeObjectReference.class);
139+
nativeObjectWrapperList = new ReferenceStack<>();
140140

141141
// avoid 0 to be used as ID
142142
int nullID = nativeObjectWrapperList.reserve();

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/common/ReferenceStack.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
*/
4141
package com.oracle.graal.python.builtins.objects.cext.common;
4242

43-
import java.lang.reflect.Array;
4443
import java.util.Arrays;
4544
import java.util.Iterator;
4645

@@ -50,11 +49,11 @@ public final class ReferenceStack<T> implements Iterable<T> {
5049
private static final int INITIAL_CAPACITY = 64;
5150

5251
private final IntegerStack freeList;
53-
private T[] nativeObjectWrapperList;
52+
private Object[] nativeObjectWrapperList;
5453

5554
@TruffleBoundary
56-
public ReferenceStack(Class<T> elementClazz) {
57-
nativeObjectWrapperList = (T[]) Array.newInstance(elementClazz, INITIAL_CAPACITY);
55+
public ReferenceStack() {
56+
nativeObjectWrapperList = new Object[INITIAL_CAPACITY];
5857
freeList = new IntegerStack(INITIAL_CAPACITY);
5958
freeList.addToFreeList(0, INITIAL_CAPACITY);
6059
}
@@ -67,14 +66,16 @@ private void enlargeNativeReferenceList() {
6766
freeList.addToFreeList(oldSize, newSize);
6867
}
6968

69+
@SuppressWarnings("unchecked")
7070
public T get(int idx) {
7171
assert 0 <= idx && idx < nativeObjectWrapperList.length;
72-
return nativeObjectWrapperList[idx];
72+
return (T) nativeObjectWrapperList[idx];
7373
}
7474

75+
@SuppressWarnings("unchecked")
7576
public T remove(int idx) {
7677
assert 0 <= idx && idx < nativeObjectWrapperList.length;
77-
T ref = nativeObjectWrapperList[idx];
78+
T ref = (T) nativeObjectWrapperList[idx];
7879
nativeObjectWrapperList[idx] = null;
7980
freeList.push(idx);
8081
return ref;
@@ -96,16 +97,18 @@ public void commit(int idx, T nativeObjectReference) {
9697
nativeObjectWrapperList[idx] = nativeObjectReference;
9798
}
9899

100+
@SuppressWarnings("unchecked")
99101
public T resurrect(int idx, T nativeObjectReference) {
100102
assert 0 <= idx && idx < nativeObjectWrapperList.length;
101-
T old = nativeObjectWrapperList[idx];
103+
T old = (T) nativeObjectWrapperList[idx];
102104
nativeObjectWrapperList[idx] = nativeObjectReference;
103105
return old;
104106
}
105107

106108
@Override
109+
@SuppressWarnings("unchecked")
107110
public Iterator<T> iterator() {
108-
return Arrays.asList(nativeObjectWrapperList).iterator();
111+
return (Iterator<T>) Arrays.asList(nativeObjectWrapperList).iterator();
109112
}
110113

111114
static final class IntegerStack {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyContext.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ public static HPyContextMembers getByName(String name) {
327327

328328
@CompilationFinal private ReferenceQueue<Object> nativeSpaceReferenceQueue;
329329
@CompilationFinal private RootCallTarget referenceCleanerCallTarget;
330-
public final ReferenceStack<GraalHPyHandleReference> references = new ReferenceStack<>(GraalHPyHandleReference.class);
330+
public final ReferenceStack<GraalHPyHandleReference> references = new ReferenceStack<>();
331331

332332
public GraalHPyContext(PythonContext context, Object hpyLibrary) {
333333
super(context, hpyLibrary, GraalHPyConversionNodeSupplier.HANDLE);
@@ -908,7 +908,7 @@ void createHandleReference(PythonObject pythonObject, Object dataPtr, Object des
908908
private ReferenceQueue<Object> ensureReferenceQueue() {
909909
if (nativeSpaceReferenceQueue == null) {
910910
CompilerDirectives.transferToInterpreterAndInvalidate();
911-
final ReferenceQueue referenceQueue = new ReferenceQueue<>();
911+
final ReferenceQueue<Object> referenceQueue = new ReferenceQueue<>();
912912

913913
// lazily register the runnable that concurrently collects the queued references
914914
getContext().registerAsyncAction(() -> {

0 commit comments

Comments
 (0)