Skip to content

Commit c7f9fe2

Browse files
committed
Make memoryview exports a long
1 parent 6a98c68 commit c7f9fe2

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,9 @@
144144
import com.oracle.graal.python.nodes.object.IsBuiltinClassProfile;
145145
import com.oracle.graal.python.nodes.truffle.PythonArithmeticTypes;
146146
import com.oracle.graal.python.nodes.truffle.PythonTypes;
147-
import com.oracle.graal.python.nodes.util.CastToJavaIntExactNode;
147+
import com.oracle.graal.python.nodes.util.CannotCastException;
148148
import com.oracle.graal.python.nodes.util.CastToJavaIntLossyNode;
149+
import com.oracle.graal.python.nodes.util.CastToJavaLongExactNode;
149150
import com.oracle.graal.python.runtime.PythonContext;
150151
import com.oracle.graal.python.runtime.PythonOptions;
151152
import com.oracle.graal.python.runtime.exception.PException;
@@ -842,7 +843,7 @@ static int doMemoryViewFlags(PMemoryView object, @SuppressWarnings("unused") Pyt
842843
}
843844

844845
@Specialization(guards = "eq(MEMORYVIEW_EXPORTS, key)")
845-
static int doMemoryViewExports(PMemoryView object, @SuppressWarnings("unused") PythonNativeWrapper nativeWrapper, @SuppressWarnings("unused") String key) {
846+
static long doMemoryViewExports(PMemoryView object, @SuppressWarnings("unused") PythonNativeWrapper nativeWrapper, @SuppressWarnings("unused") String key) {
846847
return object.getExports().get();
847848
}
848849

@@ -1233,8 +1234,12 @@ static Object doTpDictoffset(PythonManagedClass object, @SuppressWarnings("unuse
12331234

12341235
@Specialization(guards = "eq(MEMORYVIEW_EXPORTS, key)")
12351236
static Object doMemoryViewExports(PMemoryView object, @SuppressWarnings("unused") PythonNativeWrapper nativeWrapper, @SuppressWarnings("unused") String key, Object value,
1236-
@Cached CastToJavaIntExactNode cast) {
1237-
object.getExports().set(cast.execute(value));
1237+
@Cached CastToJavaLongExactNode cast) {
1238+
try {
1239+
object.getExports().set(cast.execute(value));
1240+
} catch (CannotCastException | PException e) {
1241+
throw CompilerDirectives.shouldNotReachHere("Failed to set memoryview exports: invalid type");
1242+
}
12381243
return value;
12391244
}
12401245

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/memoryview/MemoryViewBuiltins.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,7 @@ private static boolean checkShouldReleaseBuffer(PMemoryView self) {
797797
}
798798

799799
private void checkExports(PMemoryView self) {
800-
int exports = self.getExports().get();
800+
long exports = self.getExports().get();
801801
if (exports > 0) {
802802
throw raise(BufferError, ErrorMessages.MEMORYVIEW_HAS_D_EXPORTED_BUFFERS, exports);
803803
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/memoryview/PMemoryView.java

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

4343
import static com.oracle.graal.python.builtins.PythonBuiltinClassType.ValueError;
4444

45-
import java.util.concurrent.atomic.AtomicInteger;
45+
import java.util.concurrent.atomic.AtomicLong;
4646

4747
import com.oracle.graal.python.builtins.objects.object.PythonBuiltinObject;
4848
import com.oracle.graal.python.builtins.objects.object.PythonObjectLibrary;
@@ -81,7 +81,7 @@ public final class PMemoryView extends PythonBuiltinObject {
8181
private final int[] suboffsets;
8282

8383
// Count of exports via native buffer interface
84-
private final AtomicInteger exports = new AtomicInteger();
84+
private final AtomicLong exports = new AtomicLong();
8585
// Phantom ref to this object that will decref/release the managed buffer if any
8686
private BufferReference reference;
8787
private int flags;
@@ -256,7 +256,7 @@ public int getFlags() {
256256
return flags;
257257
}
258258

259-
public AtomicInteger getExports() {
259+
public AtomicLong getExports() {
260260
return exports;
261261
}
262262

0 commit comments

Comments
 (0)