allow passing a null through a cstr arg/return

This commit is contained in:
Skgland
2025-08-08 22:45:24 +02:00
committed by Bennet Bleßmann
parent 7b960a7d63
commit e1a52a4dde
3 changed files with 36 additions and 12 deletions

View File

@@ -1,16 +1,21 @@
:- use_module(library(os)).
:- use_module(library(ffi)).
test :-
init :-
read(Body),
term_variables(Body, [LIB]),
Body,
use_foreign_module(LIB, [
'ffi_cstr_len'([cstr], u64),
'ffi_example_cstr'([], cstr)
]),
'ffi_example_cstr'([], cstr),
'ffi_null_cstr'([], cstr)
]).
test :-
ffi:'ffi_cstr_len'("Scryer Prolog", Len),
ffi:'ffi_example_cstr'(Str),
write((Len-Str)).
ffi:'ffi_null_cstr'(Null),
ffi:'ffi_cstr_len'(0, MaxU64),
write((Len-Str-Null-MaxU64)).
:- initialization(test).
:- initialization((init,test)).