add ffi:{allocate,read_ptr,deallocate}

This commit is contained in:
Skgland
2025-08-09 02:14:02 +02:00
committed by Bennet Bleßmann
parent 35d34231f2
commit 20d52c093a
9 changed files with 539 additions and 86 deletions

19
tests-pl/ffi_heap.pl Normal file
View File

@@ -0,0 +1,19 @@
:- use_module(library(os)).
:- use_module(library(ffi)).
init :-
read(Body),
term_variables(Body, [LIB]),
Body,
use_foreign_module(LIB, [
'ffi_set_u64'([ptr], void)
]).
test :-
ffi:allocate(rust, u64, 0, Ptr),
ffi:'ffi_set_u64'(Ptr),
ffi:read_ptr(u64, Ptr, Val),
ffi:deallocate(rust, u64, Ptr),
write((Val)).
:- initialization((init,test)).