Skip to content

Commit 7acf6cc

Browse files
committed
TO_NATIVE should always return self
* For simplicity, make Truffle::FFI::Struct a pointer for NFI interop, since it is only used internally. * FFI::Struct does not need to define #to_native, as it can already be converted to a pointer with FFI's #to_ptr protocol and #get_pointer_value.
1 parent ebde098 commit 7acf6cc

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

lib/truffle/truffle/ffi/ffi_struct.rb

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,19 @@ def to_ptr
256256
@pointer
257257
end
258258

259-
# For interop TO_NATIVE
259+
# Every IS_POINTER object should also have TO_NATIVE
260260
def to_native
261-
@pointer
261+
self
262+
end
263+
264+
# For NFI, to implement IS_POINTER
265+
def pointer?
266+
true
267+
end
268+
269+
# For NFI, to implement AS_POINTER
270+
def address
271+
@pointer.address
262272
end
263273

264274
def free

lib/truffle/truffle/ffi_backend/struct.rb

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,6 @@ def initialize_copy(other)
7878
end
7979
end
8080

81-
# For interop TO_NATIVE
82-
def to_native
83-
@pointer
84-
end
85-
8681
private def pointer=(pointer)
8782
unless FFI::AbstractMemory === pointer
8883
raise TypeError, "wrong argument type #{pointer.class} (expected Pointer or Buffer)"

0 commit comments

Comments
 (0)