diff --git a/include/alisp/sv.h b/include/alisp/sv.h index d5291f2..2925f85 100644 --- a/include/alisp/sv.h +++ b/include/alisp/sv.h @@ -19,6 +19,7 @@ typedef struct // String view macro constructor #define SV(DATA, SIZE) ((sv_t){.data = (DATA), .size = (SIZE)}) +#define SV_AUTO(DATA) ((sv_t){.data = (void *)(DATA), .size = sizeof(DATA) - 1}) // Pretty printers #define SV_FMT(SV) (int)(SV).size, (SV).data #define PR_SV "%.*s" diff --git a/test/test_lisp_api.c b/test/test_lisp_api.c index ed23693..b1b3083 100644 --- a/test/test_lisp_api.c +++ b/test/test_lisp_api.c @@ -84,10 +84,10 @@ void sym_unique_test(void) sys_init(&system); sv_t symbols[] = { - SV("hello", 5), - SV("goodbye", 7), - SV("display", 7), - SV("@xs'a_sh;d::a-h]", 16), + SV_AUTO("hello"), + SV_AUTO("goodbye"), + SV_AUTO("display"), + SV_AUTO("@xs'a_sh;d::a-h]"), }; lisp_t *ptrs[ARRSIZE(symbols)]; @@ -159,7 +159,7 @@ void sys_test(void) "Making integers doesn't affect system memory size"); // Creating symbols won't affect memory size, but does affect the symbol table - (void)intern(&sys, SV("hello world!", 12)); + (void)intern(&sys, SV_AUTO("hello world!")); TEST(sys.memory.size == old_memory_size, "Interning doesn't affect system memory size"); TEST(sys.symtable.count > 0, "Interning affects symbol table"); @@ -169,7 +169,7 @@ void sys_test(void) TEST(sys.memory.size > 0, "Creating conses affects memory size"); old_memory_size = sys.memory.size; - (void)cons(&sys, intern(&sys, SV("test", 4)), NIL); + (void)cons(&sys, intern(&sys, SV_AUTO("test")), NIL); TEST(sys.memory.size > old_memory_size, "Creating conses back to back affects memory size"); old_memory_size = sys.memory.size; diff --git a/test/test_stream.c b/test/test_stream.c index 0be6d80..8b15db1 100644 --- a/test/test_stream.c +++ b/test/test_stream.c @@ -64,8 +64,8 @@ void stream_test_string(void) { TEST_START(); sv_t test_strings[] = { - SV("hello, world!", 13), - SV("another string", 14), + SV_AUTO("hello, world!"), + SV_AUTO("another string"), SV((char *)text, ARRSIZE(text) / 2), };