diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2020-01-08 00:49:00 +0000 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2020-01-08 00:49:00 +0000 |
commit | 12fd1d7637c2fe5a4a6361aeb0f23997880cf1e2 (patch) | |
tree | 4729e3c6e2756d30cb145ccea6ff91bec97c8a26 /tests | |
parent | e9ddfed55490cc9f41f700fb98340fa6a9536aaa (diff) | |
download | txr-12fd1d7637c2fe5a4a6361aeb0f23997880cf1e2.tar.gz txr-12fd1d7637c2fe5a4a6361aeb0f23997880cf1e2.tar.bz2 txr-12fd1d7637c2fe5a4a6361aeb0f23997880cf1e2.zip |
tests: broken glob test cases crash under musl.
Among several issues, the main one is that these
test cases use the str-d FFI type for strings.
This type means that TXR will take ownership of the
memory; it creates the Lisp strings for the Lisp array,
and then assuming that it has owership of the C strings,
it will free them. On musl, this causes an instant crash,
probably because the strings might not be individually
coming from malloc. The only documented interface for
freing glob resources is globfree; programs cannot assume
that the strings can be freed.
* tests/017/glob-carray.expected: Updated.
* tests/017/glob-carray.tl (glob-t): Add missing flags member
of type int. Change the array element string type from str-d
to str.
* tests/017/glob-zarray.tl: Likewise, and also add a comment
to explain why we are not calling globfree in this test case.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/017/glob-carray.expected | 2 | ||||
-rw-r--r-- | tests/017/glob-carray.tl | 7 | ||||
-rw-r--r-- | tests/017/glob-zarray.tl | 19 |
3 files changed, 21 insertions, 7 deletions
diff --git a/tests/017/glob-carray.expected b/tests/017/glob-carray.expected index cf4b8a5e..996151ee 100644 --- a/tests/017/glob-carray.expected +++ b/tests/017/glob-carray.expected @@ -1,4 +1,4 @@ 0 -#S(glob-t pathc 5 pathv #<carray 5 #<ffi-type str-d>> reserve 0) +#S(glob-t pathc 5 pathv #<carray 5 #<ffi-type str>> reserve 0) #("tests/001/query-1.txr" "tests/001/query-2.txr" "tests/001/query-3.txr" "tests/001/query-4.txr" "tests/001/query-5.txr") diff --git a/tests/017/glob-carray.tl b/tests/017/glob-carray.tl index d40dfdad..99660576 100644 --- a/tests/017/glob-carray.tl +++ b/tests/017/glob-carray.tl @@ -10,7 +10,7 @@ (nil int) (nil size-t) (nil int) - (pathv (carray str-d)) + (pathv (carray str)) (nil (array 4 cptr))))) ((:cygnal :cygwin) (deffi-type glob-t (struct glob-t @@ -18,12 +18,13 @@ (nil size-t) (nil size-t) (nil int) - (pathv (carray str-d)) + (pathv (carray str)) (nil (array 6 cptr))))) (t (deffi-type glob-t (struct glob-t (pathc size-t) - (pathv (carray str-d)) + (pathv (carray str)) (reserve size-t) + (nil int) (nil (array 5 cptr)))))) (with-dyn-lib (libc) diff --git a/tests/017/glob-zarray.tl b/tests/017/glob-zarray.tl index 81d11bf8..b095e45e 100644 --- a/tests/017/glob-zarray.tl +++ b/tests/017/glob-zarray.tl @@ -10,7 +10,7 @@ (nil int) (nil size-t) (nil int) - (pathv (ptr-out-d (zarray str-d))) + (pathv (ptr-out (zarray str))) (nil (array 4 cptr))))) ((:cygnal :cygwin) (deffi-type glob-t (struct glob-t @@ -18,18 +18,31 @@ (nil size-t) (nil size-t) (nil int) - (pathv (ptr-out-d (zarray str-d))) + (pathv (ptr-out (zarray str))) (nil (array 6 cptr))))) (t (deffi-type glob-t (struct glob-t (pathc size-t) - (pathv (ptr-out-d (zarray str-d))) + (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)) |