From af8b7db50fcc3ed34bfe1136d1664d59e89ba1a9 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Mon, 21 Mar 2022 06:16:43 -0700 Subject: New FFI types str-s, bstr-s and wstr-s. These types actually make it possible to receive a string by pointer from a C function, without trying to free it. It is now possible to write a FFI wrapper for strtol or wcstol, which is done in the new test case. * ffi.c (str_s_s, bstr_s_s, wstr_s_s): New symbol variables. (ffi_init_types): Register the types str-s, bstr-s and wstr-s. (ffi_init): Intern the new symbols. * tests/017/str-s.tl: New file. * txr.1: Documented. * stdlib/doc-syms.tl: Updated. --- tests/017/str-s.tl | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 tests/017/str-s.tl (limited to 'tests/017/str-s.tl') diff --git a/tests/017/str-s.tl b/tests/017/str-s.tl new file mode 100644 index 00000000..bb9dc38a --- /dev/null +++ b/tests/017/str-s.tl @@ -0,0 +1,11 @@ +(load "../common") + +(with-dyn-lib nil + (deffi strtol "strtol" long (str (ptr-out (array 1 str-s)) int)) + (deffi bcstol "strtol" long (bstr (ptr-out (array 1 bstr-s)) int)) + (deffi wcstol "wcstol" long (wstr (ptr-out (array 1 wstr-s)) int))) + +(mtest + (let ((v (vec nil))) (list (strtol "-345x" v 0) v)) (-345 #("x")) + (let ((v (vec nil))) (list (bcstol "-345x" v 0) v)) (-345 #("x")) + (let ((v (vec nil))) (list (wcstol "-345x" v 0) v)) (-345 #("x"))) -- cgit v1.2.3