summaryrefslogtreecommitdiffstats
path: root/tests/017/glob-zarray.tl
blob: e3f6d08b8dbd2ca2c262c32c98fdfd22079a034b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
(load "../common")

(defstruct glob-t nil
  pathc pathv (reserve 0))

(caseq (os-symbol)
  (:macos
    (deffi-type glob-t (struct glob-t
                         (pathc size-t)
                         (nil int)
                         (nil size-t)
                         (nil int)
                         (pathv (ptr-out (zarray str)))
                         (nil (array 4 cptr)))))
  ((:cygnal :cygwin :android)
    (deffi-type glob-t (struct glob-t
                         (pathc size-t)
                         (nil size-t)
                         (nil size-t)
                         (nil int)
                         (pathv (ptr-out (zarray str)))
                         (nil (array 6 cptr)))))
  (t (deffi-type glob-t (struct glob-t
                          (pathc size-t)
                          (pathv (ptr-out (zarray str)))
                          (reserve size-t)
                          (nil int)
                          (nil (array 5 cptr))))))

(with-dyn-lib (libc)
  (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))

;; Note: we deliberately don't call (globfree g) in this
;; test case because it won't reliably work. The problem is
;; that FFI will create a brand new C struct and populate
;; the array with newly allocated strings.
;;
;; In the glob-carray.tl test case, we do call globfree.
;; Though a different C struct is allocated, which makes
;; that usage not strictly correct, that structure is
;; populated with the original string pointers due to the
;; carray type being used.
;;
(let* ((g (new glob-t)))
  (prinl (globb "tests/001/*.txr" 0 (glob-cb (lambda (path err))) g))
  (prinl g))