Skip to content

Commit 9bd89ae

Browse files
committed
Add a bit of docs
1 parent 41089c4 commit 9bd89ae

File tree

4 files changed

+18
-8
lines changed

4 files changed

+18
-8
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/PyCArgObject.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,4 @@ public PyCArgObject(Object cls, Shape instanceShape) {
6363
obj = null;
6464
valuePointer = Pointer.NULL;
6565
}
66-
6766
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/memory/Pointer.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@
5151
import com.oracle.truffle.api.library.ExportLibrary;
5252
import com.oracle.truffle.api.library.ExportMessage;
5353

54+
/**
55+
* Pointer abstraction that should be accessed through {@link PointerNodes}. It supports storing
56+
* byte-based data or other pointers, both of which can be converted in-place to native memory if
57+
* needed (and native access is enabled).
58+
*/
5459
@ExportLibrary(InteropLibrary.class)
5560
public final class Pointer implements TruffleObject {
5661
public static final Pointer NULL = new Pointer(new NullStorage(), 0);
@@ -95,7 +100,7 @@ public static Pointer nativeMemory(Object nativePointer) {
95100
if (nativePointer instanceof Long value) {
96101
return nativeMemory((long) value);
97102
}
98-
return new Pointer(new NFIPointerStorage(nativePointer), 0);
103+
return new Pointer(new ObjectPointerStorage(nativePointer), 0);
99104
}
100105

101106
public static Pointer pythonObject(Object object) {
@@ -258,10 +263,10 @@ public LongPointerStorage(long pointer) {
258263
}
259264
}
260265

261-
static final class NFIPointerStorage extends Storage {
266+
static final class ObjectPointerStorage extends Storage {
262267
final Object pointer;
263268

264-
public NFIPointerStorage(Object pointer) {
269+
public ObjectPointerStorage(Object pointer) {
265270
this.pointer = pointer;
266271
}
267272
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/memory/PointerNodes.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
import com.oracle.graal.python.builtins.modules.ctypes.memory.Pointer.LongPointerStorage;
1010
import com.oracle.graal.python.builtins.modules.ctypes.memory.Pointer.MemoryBlock;
1111
import com.oracle.graal.python.builtins.modules.ctypes.memory.Pointer.MemoryViewStorage;
12-
import com.oracle.graal.python.builtins.modules.ctypes.memory.Pointer.NFIPointerStorage;
1312
import com.oracle.graal.python.builtins.modules.ctypes.memory.Pointer.NullStorage;
13+
import com.oracle.graal.python.builtins.modules.ctypes.memory.Pointer.ObjectPointerStorage;
1414
import com.oracle.graal.python.builtins.modules.ctypes.memory.Pointer.PointerArrayStorage;
1515
import com.oracle.graal.python.builtins.modules.ctypes.memory.Pointer.PythonObjectStorage;
1616
import com.oracle.graal.python.builtins.modules.ctypes.memory.Pointer.Storage;
@@ -660,7 +660,7 @@ public final Object execute(Node inliningTarget, Pointer ptr) {
660660
protected abstract Object execute(Node inliningTarget, MemoryBlock memory, Storage storage, int offset);
661661

662662
@Specialization
663-
static Object doNFIPointer(Node inliningTarget, @SuppressWarnings("unused") MemoryBlock memory, NFIPointerStorage storage, int offset) {
663+
static Object doObjectPointer(Node inliningTarget, @SuppressWarnings("unused") MemoryBlock memory, ObjectPointerStorage storage, int offset) {
664664
if (offset != 0) {
665665
throw PRaiseNode.raiseUncached(inliningTarget, NotImplementedError, ErrorMessages.CANNOT_APPLY_OFFSET_TO_AN_OBJECT_POINTER);
666666
}
@@ -679,7 +679,7 @@ public final long execute(Node inliningTarget, Pointer ptr) {
679679

680680
@Specialization
681681
@SuppressWarnings("unused")
682-
static long doNFIPointer(Node inliningTarget, MemoryBlock memory, NFIPointerStorage storage, int offset) {
682+
static long doObjectPointer(Node inliningTarget, MemoryBlock memory, ObjectPointerStorage storage, int offset) {
683683
throw PRaiseNode.raiseUncached(inliningTarget, NotImplementedError, ErrorMessages.CANNOT_CONVERT_OBJECT_POINTER_TO_NATIVE);
684684
}
685685
}
@@ -704,7 +704,7 @@ void doNativeMemory(Node inliningTarget, LongPointerStorage storage, int offset)
704704

705705
@Specialization
706706
@SuppressWarnings("unused")
707-
void doNFIPointer(NFIPointerStorage storage, int offset) {
707+
void doObjectPointer(ObjectPointerStorage storage, int offset) {
708708
/*
709709
* TODO This should call free using NFI. If it ever does, we should probably update
710710
* PointerReference to use a call target around this

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/memory/PointerReference.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
import com.oracle.graal.python.runtime.AsyncHandler;
44

5+
/**
6+
* Weak reference object that will deallocate possible native memory pointed to by a {@link Pointer}
7+
* when given referent gets garbage collected. It is not necessary to keep a reference to this
8+
* object after creating it, it stores a reference to itself into
9+
* {@link AsyncHandler.SharedFinalizer} automatically.
10+
*/
511
public class PointerReference extends AsyncHandler.SharedFinalizer.FinalizableReference {
612

713
public PointerReference(Object referent, Pointer pointer, AsyncHandler.SharedFinalizer sharedFinalizer) {

0 commit comments

Comments
 (0)