From 5fc47b3d24f1fa568ffb54db8e8054f190e2fb2b Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sat, 20 May 2017 21:20:34 -0700 Subject: ffi: add two tests based on glob function. One approach captures the paths as a carray of strings, and explicitly frees it with globfree. The other approach uses a zarray, taking advantage of null termination. globfree is elided because TXR FFI does the freeing; the types used declare to it that it is taking ownership of a dynamically allocated vector of dynamically allocated strings, and so it performs the equivalent of globfree. * tests/017/glob-carray.expected: New file. * tests/017/glob-carray.tl: Likewise. * tests/017/glob-zarray.expected: Likewise. * tests/017/glob-zarray.tl: Likewise. --- tests/017/glob-carray.expected | 4 ++++ tests/017/glob-carray.tl | 21 +++++++++++++++++++++ tests/017/glob-zarray.expected | 3 +++ tests/017/glob-zarray.tl | 17 +++++++++++++++++ 4 files changed, 45 insertions(+) create mode 100644 tests/017/glob-carray.expected create mode 100644 tests/017/glob-carray.tl create mode 100644 tests/017/glob-zarray.expected create mode 100644 tests/017/glob-zarray.tl (limited to 'tests/017') diff --git a/tests/017/glob-carray.expected b/tests/017/glob-carray.expected new file mode 100644 index 00000000..ac1290e3 --- /dev/null +++ b/tests/017/glob-carray.expected @@ -0,0 +1,4 @@ +0 +#S(glob-t pathc 4 pathv #> reserve 0) +#("tests/001/query-1.txr" "tests/001/query-2.txr" "tests/001/query-3.txr" + "tests/001/query-4.txr") diff --git a/tests/017/glob-carray.tl b/tests/017/glob-carray.tl new file mode 100644 index 00000000..3c68ac1a --- /dev/null +++ b/tests/017/glob-carray.tl @@ -0,0 +1,21 @@ +(load "../common") + +(defstruct glob-t nil + pathc pathv reserve) + +(deffi-type glob-t (struct glob-t + (pathc size-t) + (pathv (carray str-d)) + (reserve size-t))) + +(with-dyn-lib nil + (deffi globb "glob" int (str int closure (ptr-out glob-t))) + (deffi globfree "globfree" void ((ptr-in glob-t))) + (deffi-cb glob-cb int (str int) -1)) + +(let* ((g (new glob-t))) + (prinl (globb "tests/001/*.txr" 0 (glob-cb (lambda (path err))) g)) + (carray-set-length g.pathv g.pathc) + (prinl g) + (prinl (vec-carray g.pathv)) + (globfree g)) diff --git a/tests/017/glob-zarray.expected b/tests/017/glob-zarray.expected new file mode 100644 index 00000000..4bfc0810 --- /dev/null +++ b/tests/017/glob-zarray.expected @@ -0,0 +1,3 @@ +0 +#S(glob-t pathc 4 pathv #("tests/001/query-1.txr" "tests/001/query-2.txr" "tests/001/query-3.txr" + "tests/001/query-4.txr") reserve 0) diff --git a/tests/017/glob-zarray.tl b/tests/017/glob-zarray.tl new file mode 100644 index 00000000..b6e16d13 --- /dev/null +++ b/tests/017/glob-zarray.tl @@ -0,0 +1,17 @@ +(load "../common") + +(defstruct glob-t nil + pathc pathv reserve) + +(deffi-type glob-t (struct glob-t + (pathc size-t) + (pathv (ptr-out-d (zarray str-d))) + (reserve size-t))) + +(with-dyn-lib (libc) + (deffi globb "glob" int (str int closure (ptr-out glob-t))) + (deffi-cb glob-cb int (str int) -1)) + +(let* ((g (new glob-t))) + (prinl (globb "tests/001/*.txr" 0 (glob-cb (lambda (path err))) g)) + (prinl g)) -- cgit v1.2.3