Skip to content

Commit 68f3629

Browse files
committed
Simpler pointer operations
1 parent 9b61959 commit 68f3629

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

src/main/java/org/truffleruby/extra/ffi/Pointer.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,6 @@ public Pointer(long address, long size) {
6060
this.size = size;
6161
}
6262

63-
public Pointer realloc(long size) {
64-
return new Pointer(UNSAFE.reallocateMemory(address, size));
65-
}
66-
6763
public void writeByte(long offset, byte b) {
6864
assert address + offset != 0;
6965
UNSAFE.putByte(address + offset, b);
@@ -316,6 +312,18 @@ public int hashCode() {
316312
return Long.hashCode(address);
317313
}
318314

315+
public static long rawMalloc(long size) {
316+
return UNSAFE.allocateMemory(size);
317+
}
318+
319+
public static long rawRealloc(long address, long size) {
320+
return UNSAFE.reallocateMemory(address, size);
321+
}
322+
323+
public static void rawFree(long address) {
324+
UNSAFE.freeMemory(address);
325+
}
326+
319327
@SuppressWarnings("restriction")
320328
private static Unsafe getUnsafe() {
321329
try {

src/main/java/org/truffleruby/extra/ffi/PointerNodes.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -932,8 +932,8 @@ public DynamicObject writePointer(long address, long value) {
932932
public static abstract class PointerRawMallocPrimitiveNode extends PrimitiveArrayArgumentsNode {
933933

934934
@Specialization
935-
public long malloc(long size) {
936-
return Pointer.malloc(size).getAddress();
935+
public long realloc(long size) {
936+
return Pointer.rawMalloc(size);
937937
}
938938

939939
}
@@ -943,7 +943,7 @@ public static abstract class PointerRawReallocPrimitiveNode extends PrimitiveArr
943943

944944
@Specialization
945945
public long malloc(long address, long size) {
946-
return new Pointer(address).realloc(size).getAddress();
946+
return Pointer.rawRealloc(address, size);
947947
}
948948

949949
}
@@ -953,7 +953,7 @@ public static abstract class PointerRawFreePrimitiveNode extends PrimitiveArrayA
953953

954954
@Specialization
955955
public long free(long address) {
956-
new Pointer(address).free();
956+
Pointer.rawFree(address);
957957
return address;
958958
}
959959

0 commit comments

Comments
 (0)