Browse Source

Fix tests C compile

I don't understand why I can't get strdup defined in Dictionary.cake.
master
Macoy Madson 3 months ago
parent
commit
c065a390cc
  1. 4
      src/Dictionary.cake
  2. 15
      src/Introspection.cake

4
src/Dictionary.cake

@ -566,7 +566,7 @@
(comptime-cond
('auto-test
(c-import "stdio.h")
(c-import "<stdio.h>" "<string.h>")
(defun test--dictionary (&return int)
(scope ;; Simple key value entries
(defstruct dictionary-entry
@ -613,6 +613,8 @@
(var my-dictionary (addr complex-dictionary-entry) null)
(strdict-use-key-arena my-dictionary)
(declare-extern-function strdup (str (addr (const char)) &return (addr char)))
(var items (array complex-dictionary-entry)
(array
(array (strdup "cakelisp") "programming language" "cakelisp is a programming language")

15
src/Introspection.cake

@ -1,5 +1,8 @@
(import "FileUtilities.cake"
"CHelpers.cake" "ComptimeHelpers.cake")
(comptime-cond
('Unix
(c-preprocessor-define __USE_XOPEN_EXTENDED))) ;; for strdup
(c-import "<stdlib.h>" ;; atoi, atof
"<string.h>" ;; strcmp
"<ctype.h>" ;; For isspace
@ -1829,9 +1832,12 @@
(ignore))
(defun test--introspection (&return int)
;; (declare-extern-function strdup (str (addr (const char)) &return (addr char)))
(var another-name (addr char) (strdup "Another name"))
(defer (free another-name))
(var a my-struct
(array #"#"Hello!" This is a naughty
naughty string with \\ backslashes and such \\#"# "Other name" (strdup "Another name") null
naughty string with \\ backslashes and such \\#"# "Other name" another-name null
42 -0.33f (array 0.f 1.f 2.f) (array 10.f 20.f 30.f)
(array (array "Hi" true) (array "Bye" false))
false 'a'
@ -1906,7 +1912,7 @@
(scope ;; Copy structs
(var a-2 my-struct
(array "Test struct" "Other name" (strdup "Another name") null
(array "Test struct" "Other name" another-name null
42 -0.33f (array 0.f 1.f 2.f) (array 10.f 20.f 30.f)
(array (array "Hi" true) (array "Bye" false))
false 'a'
@ -1925,8 +1931,7 @@
(fprintf stderr "error: copied struct does not equal baseline\n")
(return 1))
(free-introspect-struct-fields
my-struct--metadata (addr b) free)
(free (field a-2 yet-another-name)))
my-struct--metadata (addr b) free))
(scope ;; Test errors
(var read-struct my-struct (array 0))
@ -1948,6 +1953,4 @@
(free-introspect-struct-fields
my-struct--metadata (addr read-struct) free)))
(free (field a yet-another-name))
(return 0))))

Loading…
Cancel
Save