diff --git a/c3s/c3s.c b/c3s/c3s.c
index cae8f18..129b6a3 100644
--- a/c3s/c3s.c
+++ b/c3s/c3s.c
@@ -64,8 +64,10 @@ int main (int argc, char **argv)
s_module c3;
s_env env;
s_facts facts;
+ s8 i[BUF_SIZE];
s_buf in;
s_tag input;
+ s8 o[BUF_SIZE];
s_buf out;
sw r;
s_tag result;
@@ -74,9 +76,9 @@ int main (int argc, char **argv)
c3_init(&c3, &facts);
if (argc < 1)
return usage(argv[0]);
- BUF_INIT_ALLOCA(&in, BUFSZ);
+ buf_init(&in, false, sizeof(i), i);
buf_file_open_r(&in, stdin);
- BUF_INIT_ALLOCA(&out, BUFSZ);
+ buf_init(&out, false, sizeof(o), o);
buf_file_open_w(&out, stdout);
env_init(&env);
while ((r = buf_xfer_spaces(&out, &in)) >= 0) {
diff --git a/ic3/ic3.c b/ic3/ic3.c
index ed8815c..b43a2e8 100644
--- a/ic3/ic3.c
+++ b/ic3/ic3.c
@@ -64,8 +64,10 @@ int main (int argc, char **argv)
s_module c3;
s_env env;
s_facts facts;
+ s8 i[BUF_SIZE];
s_buf in;
s_tag input;
+ s8 o[BUF_SIZE];
s_buf out;
sw r;
s_tag result;
@@ -74,10 +76,10 @@ int main (int argc, char **argv)
c3_init(&c3, &facts);
if (argc < 1)
return usage(argv[0]);
- BUF_INIT_ALLOCA(&in, BUFSZ);
+ buf_init(&in, false, sizeof(i), i);
buf_linenoise_open_r(&in, "ic3> ");
in.line = 0;
- BUF_INIT_ALLOCA(&out, BUFSZ);
+ buf_init(&out, false, sizeof(o), o);
buf_file_open_w(&out, stdout);
env_init(&env);
while ((r = buf_xfer_spaces(&out, &in)) >= 0) {
diff --git a/libc3/buf.h b/libc3/buf.h
index 314dbf8..ef0a5f7 100644
--- a/libc3/buf.h
+++ b/libc3/buf.h
@@ -26,17 +26,6 @@
#include <stdlib.h>
#include "types.h"
-#define BUF_INIT_ALLOCA(buf, size) \
- do { \
- s8 *p; \
- assert(buf); \
- assert(size); \
- p = alloca(size); \
- if (!p) \
- err(1, "out of memory"); \
- buf_init((buf), false, (size), p); \
- } while (0)
-
#define BUF_SIZE 1024
extern const sw buf_u8_to_hex_size;
diff --git a/libc3/buf_inspect.c b/libc3/buf_inspect.c
index cb5031b..69a275d 100644
--- a/libc3/buf_inspect.c
+++ b/libc3/buf_inspect.c
@@ -124,8 +124,9 @@ sw buf_inspect_f32 (s_buf *buf, f32 x)
sw buf_inspect_f32_size (f32 x)
{
+ s8 b[16];
s_buf buf;
- BUF_INIT_ALLOCA(&buf, 16);
+ buf_init(&buf, false, sizeof(b), b);
return buf_inspect_f32(&buf, x);
}
@@ -136,8 +137,9 @@ sw buf_inspect_f64 (s_buf *buf, f64 x)
sw buf_inspect_f64_size (f64 x)
{
+ s8 b[16];
s_buf buf;
- BUF_INIT_ALLOCA(&buf, 16);
+ buf_init(&buf, false, sizeof(b), b);
return buf_inspect_f64(&buf, x);
}
@@ -587,6 +589,7 @@ sw buf_inspect_str_byte (s_buf *buf, u8 x)
sw buf_inspect_str_character (s_buf *buf, character x)
{
+ s8 b[4];
s_buf char_buf;
int i;
int j;
@@ -608,7 +611,7 @@ sw buf_inspect_str_character (s_buf *buf, character x)
case '\'': if ((r = buf_write_u8(buf, '\'')) < 0) return r; break;
case '\\': if ((r = buf_write_u8(buf, '\\')) < 0) return r; break;
default:
- BUF_INIT_ALLOCA(&char_buf, 4);
+ buf_init(&char_buf, false, sizeof(b), b);
if ((i = buf_write_character_utf8(&char_buf, x)) < 0)
return i;
j = 0;
@@ -915,8 +918,9 @@ sw buf_inspect_u8 (s_buf *buf, u8 x)
sw i;
sw r;
sw size = 0;
+ s8 t[3];
s_buf tmp;
- BUF_INIT_ALLOCA(&tmp, 3);
+ buf_init(&tmp, false, sizeof(t), t);
if (x == 0)
return buf_write_u8(buf, '0');
while (x > 0) {
@@ -952,8 +956,9 @@ sw buf_inspect_u16 (s_buf *buf, u16 x)
sw i;
sw r;
sw size = 0;
+ s8 t[5];
s_buf tmp;
- BUF_INIT_ALLOCA(&tmp, 5);
+ buf_init(&tmp, false, sizeof(t), t);
if (x == 0)
return buf_write_u8(buf, '0');
while (x > 0) {
@@ -989,8 +994,9 @@ sw buf_inspect_u32 (s_buf *buf, u32 x)
sw i;
sw r;
sw size = 0;
+ s8 t[10];
s_buf tmp;
- BUF_INIT_ALLOCA(&tmp, 10);
+ buf_init(&tmp, false, sizeof(t), t);
if (x == 0)
return buf_write_u8(buf, '0');
while (x > 0) {
@@ -1026,8 +1032,9 @@ sw buf_inspect_u64 (s_buf *buf, u64 x)
sw i;
sw r;
sw size = 0;
+ s8 t[20];
s_buf tmp;
- BUF_INIT_ALLOCA(&tmp, 20);
+ buf_init(&tmp, false, sizeof(t), t);
if (x == 0)
return buf_write_u8(buf, '0');
while (x > 0) {
diff --git a/libc3/buf_parse.c b/libc3/buf_parse.c
index 107f925..0c071bf 100644
--- a/libc3/buf_parse.c
+++ b/libc3/buf_parse.c
@@ -551,6 +551,7 @@ sw buf_parse_ident (s_buf *buf, s_ident *dest)
sw result = 0;
s_buf_save save;
s_str str;
+ s8 t[IDENT_MAX];
s_buf tmp;
assert(buf);
assert(dest);
@@ -581,7 +582,7 @@ sw buf_parse_ident (s_buf *buf, s_ident *dest)
goto restore;
if (r > 0 && ! ident_first_character_is_reserved(c)) {
csize = r;
- BUF_INIT_ALLOCA(&tmp, IDENT_MAX);
+ buf_init(&tmp, false, sizeof(t), t);
if ((r = buf_xfer(&tmp, buf, csize)) < 0)
goto restore;
result += csize;
@@ -1175,13 +1176,14 @@ sw buf_parse_str_u8 (s_buf *buf, u8 *dest)
sw buf_parse_sym (s_buf *buf, const s_sym **dest)
{
- s_buf tmp;
character c;
sw csize;
sw r;
sw result = 0;
s_buf_save save;
s_str str;
+ s8 t[SYM_MAX];
+ s_buf tmp;
assert(buf);
assert(dest);
buf_save_init(buf, &save);
@@ -1203,7 +1205,7 @@ sw buf_parse_sym (s_buf *buf, const s_sym **dest)
goto clean;
if (c == ':' || character_is_uppercase(c)) {
csize = r;
- BUF_INIT_ALLOCA(&tmp, SYM_MAX);
+ buf_init(&tmp, false, sizeof(t), t);
if (c == ':') {
if ((r = buf_ignore(buf, csize)) < 0)
goto clean;
diff --git a/libc3/facts.c b/libc3/facts.c
index fc34cf5..fd7e1fa 100644
--- a/libc3/facts.c
+++ b/libc3/facts.c
@@ -143,12 +143,13 @@ sw facts_dump (const s_facts *facts, s_buf *buf)
sw facts_dump_file (const s_facts *facts, const s8 *path)
{
+ s8 b[BUF_SIZE];
s_buf buf;
FILE *fp;
sw r;
assert(facts);
assert(path);
- BUF_INIT_ALLOCA(&buf, 1024);
+ buf_init(&buf, false, sizeof(b), b);
if (! (fp = fopen(path, "wb"))) {
warn("fopen: %s", path);
return -1;
@@ -274,12 +275,13 @@ sw facts_load (s_facts *facts, s_buf *buf)
sw facts_load_file (s_facts *facts, const s8 *path)
{
+ s8 b[BUF_SIZE];
s_buf buf;
FILE *fp;
sw result;
assert(facts);
assert(path);
- BUF_INIT_ALLOCA(&buf, 1024);
+ buf_init(&buf, false, sizeof(b), b);
fp = fopen(path, "r");
buf_file_open_r(&buf, fp);
result = facts_load(facts, &buf);
@@ -357,10 +359,11 @@ sw facts_open_buf (s_facts *facts, s_buf *buf)
sw facts_open_file (s_facts *facts, const s8 *path)
{
FILE *fp;
+ s8 i[BUF_SIZE];
s_buf in;
sw r;
sw result = 0;
- BUF_INIT_ALLOCA(&in, BUF_SIZE);
+ buf_init(&in, false, sizeof(i), i);
if (! (fp = fopen(path, "rb"))) {
if (errno == ENOENT)
return facts_open_file_create(facts, path);
@@ -482,6 +485,7 @@ e_bool facts_remove_fact (s_facts *facts, const s_fact *fact)
sw facts_save_file (s_facts *facts, const s8 *path)
{
+ s8 b[BUF_SIZE];
s_buf buf;
FILE *fp;
sw r;
@@ -489,7 +493,7 @@ sw facts_save_file (s_facts *facts, const s8 *path)
assert(facts);
assert(path);
assert(! facts->log);
- BUF_INIT_ALLOCA(&buf, BUF_SIZE);
+ buf_init(&buf, false, sizeof(b), b);
if (! (fp = fopen(path, "wb"))) {
warn("fopen: %s", path);
return -1;
diff --git a/libc3/skiplist.h.in b/libc3/skiplist.h.in
index 6d9d85b..ee97918 100644
--- a/libc3/skiplist.h.in
+++ b/libc3/skiplist.h.in
@@ -29,10 +29,6 @@
#define SKIPLIST_SIZE___NAME$(max_height) \
(sizeof(s_skiplist___NAME$) + (max_height) * sizeof(t_skiplist_height))
-#define SKIPLIST_INIT_ALLOCA___NAME$(max_height, spacing) \
- (skiplist_init___NAME$(alloca(SKIPLIST_SIZE___NAME$(max_height)), \
- (max_height), (spacing)))
-
void
skiplist_clean___NAME$ (s_skiplist___NAME$ *skiplist);
diff --git a/libc3/skiplist__fact.h b/libc3/skiplist__fact.h
index b275df4..20f97e6 100644
--- a/libc3/skiplist__fact.h
+++ b/libc3/skiplist__fact.h
@@ -29,10 +29,6 @@
#define SKIPLIST_SIZE__fact(max_height) \
(sizeof(s_skiplist__fact) + (max_height) * sizeof(t_skiplist_height))
-#define SKIPLIST_INIT_ALLOCA__fact(max_height, spacing) \
- (skiplist_init__fact(alloca(SKIPLIST_SIZE__fact(max_height)), \
- (max_height), (spacing)))
-
void
skiplist_clean__fact (s_skiplist__fact *skiplist);
diff --git a/test/buf_file_test.c b/test/buf_file_test.c
index 29ba740..a1e3084 100644
--- a/test/buf_file_test.c
+++ b/test/buf_file_test.c
@@ -30,11 +30,12 @@ void buf_file_test ()
void buf_file_test_open_r_close ()
{
+ s8 b[16];
s_buf buf;
FILE *fp;
fp = fopen("/dev/null", "r");
assert(fp);
- BUF_INIT_ALLOCA(&buf, 16);
+ buf_init(&buf, false, sizeof(b), b);
TEST_EQ(buf_file_open_r(&buf, fp), &buf);
buf_file_close(&buf);
test_ok();
@@ -44,13 +45,14 @@ void buf_file_test_open_r_close ()
void buf_file_test_open_r_refill ()
{
u8 b = 0x80;
+ s8 bu[16];
s_buf buf;
FILE *fp;
sw i = 64;
test_context("buf_file_open_r_refill(/dev/zero)");
fp = fopen("/dev/zero", "r");
assert(fp);
- BUF_INIT_ALLOCA(&buf, 16);
+ buf_init(&buf, false, sizeof(bu), bu);
buf_file_open_r(&buf, fp);
while (i--) {
TEST_EQ(buf_read_u8(&buf, &b), 1);
diff --git a/test/buf_inspect_test.c b/test/buf_inspect_test.c
index 392c5ab..7274987 100644
--- a/test/buf_inspect_test.c
+++ b/test/buf_inspect_test.c
@@ -18,9 +18,10 @@
#define BUF_INSPECT_TEST_BOOL(test, expected) \
do { \
+ s8 b[16]; \
s_buf buf; \
test_context("buf_inspect_bool(" # test ") -> " # expected); \
- BUF_INIT_ALLOCA(&buf, 16); \
+ buf_init(&buf, false, sizeof(b), b); \
TEST_EQ(buf_inspect_bool(&buf, (test)), strlen(expected)); \
TEST_STRNCMP(buf.ptr.p, (expected), buf.wpos); \
test_context(NULL); \
@@ -39,9 +40,10 @@
#define BUF_INSPECT_TEST_F32(test, expected) \
do { \
+ s8 b[32]; \
s_buf buf; \
test_context("buf_inspect_f32(" # test ") -> " # expected); \
- BUF_INIT_ALLOCA(&buf, 32); \
+ buf_init(&buf, false, sizeof(b), b); \
TEST_EQ(buf_inspect_f32_size(test), strlen(expected)); \
TEST_EQ(buf_inspect_f32(&buf, test), strlen(expected)); \
TEST_STRNCMP(buf.ptr.ps8, (expected), buf.wpos); \
@@ -50,9 +52,10 @@
#define BUF_INSPECT_TEST_F64(test, expected) \
do { \
+ s8 b[64]; \
s_buf buf; \
test_context("buf_inspect_f64(" # test ") -> " # expected); \
- BUF_INIT_ALLOCA(&buf, 64); \
+ buf_init(&buf, false, sizeof(b), b); \
TEST_EQ(buf_inspect_f64_size(test), strlen(expected)); \
TEST_EQ(buf_inspect_f64(&buf, test), strlen(expected)); \
TEST_STRNCMP(buf.ptr.ps8, (expected), buf.wpos); \
diff --git a/test/buf_test.c b/test/buf_test.c
index bbc4cce..2b0050c 100644
--- a/test/buf_test.c
+++ b/test/buf_test.c
@@ -214,8 +214,9 @@ void buf_test ()
void buf_test_f ()
{
+ s8 b[32];
s_buf buf;
- BUF_INIT_ALLOCA(&buf, 32);
+ buf_init(&buf, false, sizeof(b), b); \
BUF_TEST_F(buf_f(&buf, "09AZaz"), "09AZaz");
BUF_TEST_F(buf_f(&buf, "%d", 0), "0");
BUF_TEST_F(buf_f(&buf, "%d", 42), "42");
@@ -253,23 +254,23 @@ void buf_test_init_clean ()
char a[4] = "test";
size_t len;
char *m;
- s_buf bufa;
+ s_buf buf;
len = 4;
- buf_init(&bufa, false, len, a);
- TEST_EQ(bufa.size, len);
- TEST_EQ(strncmp(bufa.ptr.p, "test", len), 0);
- TEST_EQ(bufa.rpos, 0);
- TEST_EQ(bufa.wpos, 0);
- BUF_TEST_CLEAN(bufa);
+ buf_init(&buf, false, len, a);
+ TEST_EQ(buf.size, len);
+ TEST_EQ(strncmp(buf.ptr.p, "test", len), 0);
+ TEST_EQ(buf.rpos, 0);
+ TEST_EQ(buf.wpos, 0);
+ BUF_TEST_CLEAN(buf);
len = 4;
m = malloc(len);
memcpy(m, "test", len);
- buf_init(&bufa, true, len, m);
- TEST_EQ(bufa.size, len);
- TEST_EQ(strncmp(bufa.ptr.p, "test", len), 0);
- TEST_EQ(bufa.rpos, 0);
- TEST_EQ(bufa.wpos, 0);
- BUF_TEST_CLEAN(bufa);
+ buf_init(&buf, true, len, m);
+ TEST_EQ(buf.size, len);
+ TEST_EQ(strncmp(buf.ptr.p, "test", len), 0);
+ TEST_EQ(buf.rpos, 0);
+ TEST_EQ(buf.wpos, 0);
+ BUF_TEST_CLEAN(buf);
}
void buf_test_new_delete ()
@@ -359,9 +360,10 @@ void buf_test_peek_s8 ()
void buf_test_peek_s16 ()
{
+ s8 b[8];
s_buf buf;
s16 val;
- BUF_INIT_ALLOCA(&buf, 8);
+ buf_init(&buf, false, sizeof(b), b); \
TEST_EQ(buf_write_s16(&buf, 0), 2);
TEST_EQ(buf.rpos, 0);
TEST_EQ(buf.wpos, 2);
@@ -431,9 +433,10 @@ void buf_test_read_character_utf8 ()
void buf_test_read_f32()
{
+ s8 b[16];
s_buf buf;
f32 f;
- BUF_INIT_ALLOCA(&buf, 16);
+ buf_init(&buf, false, sizeof(b), b);
TEST_EQ(buf_write_f32(&buf, 1.0f), 4);
TEST_EQ(buf.rpos, 0);
TEST_EQ(buf.wpos, 4);
@@ -459,9 +462,10 @@ void buf_test_read_f32()
void buf_test_read_f64 ()
{
+ s8 b[32];
s_buf buf;
f64 f;
- BUF_INIT_ALLOCA(&buf, 32);
+ buf_init(&buf, false, sizeof(b), b);
TEST_EQ(buf_write_f64(&buf, 1.0), 8);
TEST_EQ(buf.rpos, 0);
TEST_EQ(buf.wpos, 8);
@@ -529,9 +533,10 @@ void buf_test_read_s8 ()
void buf_test_read_s16 ()
{
+ s8 b[8];
s_buf buf;
s16 val;
- BUF_INIT_ALLOCA(&buf, 8);
+ buf_init(&buf, false, sizeof(b), b);
TEST_EQ(buf_write_s16(&buf, 0), 2);
TEST_EQ(buf.rpos, 0);
TEST_EQ(buf.wpos, 2);
@@ -552,9 +557,10 @@ void buf_test_read_s16 ()
void buf_test_read_s32()
{
- s32 val;
+ s8 b[16];
s_buf buf;
- BUF_INIT_ALLOCA(&buf, 16);
+ s32 val;
+ buf_init(&buf, false, sizeof(b), b);
TEST_EQ(buf_write_s32(&buf, 0x00000000), 4);
TEST_EQ(buf.rpos, 0);
TEST_EQ(buf.wpos, 4);
@@ -580,9 +586,10 @@ void buf_test_read_s32()
void buf_test_read_s64()
{
- s64 val;
+ s8 b[32];
s_buf buf;
- BUF_INIT_ALLOCA(&buf, 32);
+ s64 val;
+ buf_init(&buf, false, sizeof(b), b);
TEST_EQ(buf_write_s64(&buf, 0x0000000000000000), 8);
TEST_EQ(buf.rpos, 0);
TEST_EQ(buf.wpos, 8);
@@ -649,9 +656,10 @@ void buf_test_read_u8 ()
void buf_test_read_u16()
{
+ s8 b[8];
s_buf buf;
u16 val;
- BUF_INIT_ALLOCA(&buf, 8);
+ buf_init(&buf, false, sizeof(b), b);
TEST_EQ(buf_write_u16(&buf, 0x0000), 2);
TEST_EQ(buf.rpos, 0);
TEST_EQ(buf.wpos, 2);
@@ -677,9 +685,10 @@ void buf_test_read_u16()
void buf_test_read_u32()
{
+ s8 b[16];
s_buf buf;
u32 val;
- BUF_INIT_ALLOCA(&buf, 16);
+ buf_init(&buf, false, sizeof(b), b);
TEST_EQ(buf_write_u32(&buf, 0x00000000), 4);
TEST_EQ(buf.rpos, 0);
TEST_EQ(buf.wpos, 4);
@@ -705,9 +714,10 @@ void buf_test_read_u32()
void buf_test_read_u64()
{
+ s8 b[32];
s_buf buf;
u64 val;
- BUF_INIT_ALLOCA(&buf, 32);
+ buf_init(&buf, false, sizeof(b), b);
TEST_EQ(buf_write_u64(&buf, 0x0000000000000000), 8);
TEST_EQ(buf.rpos, 0);
TEST_EQ(buf.wpos, 8);
@@ -733,8 +743,9 @@ void buf_test_read_u64()
void buf_test_write_s8 ()
{
+ s8 b[4];
s_buf buf;
- BUF_INIT_ALLOCA(&buf, 4);
+ buf_init(&buf, false, sizeof(b), b);
TEST_EQ(buf_write_s8(&buf, 0x00), 1);
TEST_EQ(buf.rpos, 0);
TEST_EQ(buf.wpos, 1);
@@ -755,8 +766,9 @@ void buf_test_write_s8 ()
void buf_test_write_s16 ()
{
+ s8 b[8];
s_buf buf;
- BUF_INIT_ALLOCA(&buf, 8);
+ buf_init(&buf, false, sizeof(b), b);
TEST_EQ(buf_write_s16(&buf, 0x0000), 2);
TEST_EQ(buf.rpos, 0);
TEST_EQ(buf.wpos, 2);
@@ -777,8 +789,9 @@ void buf_test_write_s16 ()
void buf_test_write_s32 ()
{
+ s8 b[16];
s_buf buf;
- BUF_INIT_ALLOCA(&buf, 16);
+ buf_init(&buf, false, sizeof(b), b);
TEST_EQ(buf_write_s32(&buf, 0x00000000), 4);
TEST_EQ(buf.rpos, 0);
TEST_EQ(buf.wpos, 4);
@@ -799,8 +812,9 @@ void buf_test_write_s32 ()
void buf_test_write_s64 ()
{
+ s8 b[32];
s_buf buf;
- BUF_INIT_ALLOCA(&buf, 32);
+ buf_init(&buf, false, sizeof(b), b);
TEST_EQ(buf_write_s64(&buf, 0x0000000000000000), 8);
TEST_EQ(buf.rpos, 0);
TEST_EQ(buf.wpos, 8);
@@ -821,8 +835,9 @@ void buf_test_write_s64 ()
void buf_test_write_u8 ()
{
+ s8 b[4];
s_buf buf;
- BUF_INIT_ALLOCA(&buf, 4);
+ buf_init(&buf, false, sizeof(b), b);
TEST_EQ(buf_write_u8(&buf, 0x00), 1);
TEST_EQ(buf.rpos, 0);
TEST_EQ(buf.wpos, 1);
@@ -843,8 +858,9 @@ void buf_test_write_u8 ()
void buf_test_write_u16 ()
{
+ s8 b[8];
s_buf buf;
- BUF_INIT_ALLOCA(&buf, 8);
+ buf_init(&buf, false, sizeof(b), b);
TEST_EQ(buf_write_u16(&buf, 0x0000), 2);
TEST_EQ(buf.rpos, 0);
TEST_EQ(buf.wpos, 2);
@@ -865,8 +881,9 @@ void buf_test_write_u16 ()
void buf_test_write_u32 ()
{
+ s8 b[16];
s_buf buf;
- BUF_INIT_ALLOCA(&buf, 16);
+ buf_init(&buf, false, sizeof(b), b);
TEST_EQ(buf_write_u32(&buf, 0x00000000), 4);
TEST_EQ(buf.rpos, 0);
TEST_EQ(buf.wpos, 4);
@@ -887,8 +904,9 @@ void buf_test_write_u32 ()
void buf_test_write_u64 ()
{
+ s8 b[32];
s_buf buf;
- BUF_INIT_ALLOCA(&buf, 32);
+ buf_init(&buf, false, sizeof(b), b);
TEST_EQ(buf_write_u64(&buf, 0x0000000000000000), 8);
TEST_EQ(buf.rpos, 0);
TEST_EQ(buf.wpos, 8);
@@ -913,14 +931,16 @@ void buf_test_write_str ()
void buf_test_xfer ()
{
- const char a[] = "0123456789ABCDEF";
+ const s8 a[16] = "0123456789ABCDEF";
+ s8 d[16];
s_buf dest;
+ s8 s[16];
s_buf src;
s_str str;
str_init_1(&str, NULL, a);
- BUF_INIT_ALLOCA(&src, sizeof(a));
+ buf_init(&src, false, sizeof(s), s);
buf_write_str(&src, &str);
- BUF_INIT_ALLOCA(&dest, sizeof(a));
+ buf_init(&dest, false, sizeof(d), d);
TEST_EQ(buf_xfer(&dest, &src, 0), 0);
TEST_EQ(buf_xfer(&dest, &src, 1), 1);
TEST_EQ(buf_xfer(&dest, &src, 2), 2);
diff --git a/test/skiplist__fact_test.c b/test/skiplist__fact_test.c
index b2829d0..81a4666 100644
--- a/test/skiplist__fact_test.c
+++ b/test/skiplist__fact_test.c
@@ -23,22 +23,22 @@
do { \
test_context("skiplist_insert__fact(" # test ") -> " \
# expected_length); \
- TEST_ASSERT(skiplist_insert__fact(skiplist, (test))); \
- TEST_EQ(skiplist->length, (expected_length)); \
+ TEST_ASSERT(skiplist_insert__fact(&skiplist, (test))); \
+ TEST_EQ(skiplist.length, (expected_length)); \
test_context(NULL); \
} while (0)
#define SKIPLIST__FACT_TEST_INIT_CLEAN(max_height_, spacing) \
do { \
- s_skiplist__fact *skiplist; \
- TEST_ASSERT((skiplist = SKIPLIST_INIT_ALLOCA__fact(max_height_, \
- spacing))); \
- TEST_ASSERT(skiplist->head); \
- TEST_ASSERT(skiplist->compare); \
- TEST_EQ(skiplist->length, 0); \
- TEST_EQ(skiplist->max_height, max_height_); \
- TEST_EQ(skiplist->head->height, max_height_); \
- skiplist_clean__fact(skiplist); \
+ s_skiplist__fact skiplist; \
+ TEST_ASSERT(skiplist_init__fact(&skiplist, max_height_, \
+ spacing)); \
+ TEST_ASSERT(skiplist.head); \
+ TEST_ASSERT(skiplist.compare); \
+ TEST_EQ(skiplist.length, 0); \
+ TEST_EQ(skiplist.max_height, max_height_); \
+ TEST_EQ(skiplist.head->height, max_height_); \
+ skiplist_clean__fact(&skiplist); \
test_ok(); \
} while (0)
@@ -60,8 +60,8 @@
do { \
test_context("skiplist_remove__fact(" # test ") -> " \
# expected_length); \
- skiplist_remove__fact(skiplist, (test)); \
- TEST_EQ(skiplist->length, (expected_length)); \
+ skiplist_remove__fact(&skiplist, (test)); \
+ TEST_EQ(skiplist.length, (expected_length)); \
test_context(NULL); \
} while (0)
@@ -114,25 +114,25 @@ void skiplist__fact_test_find ()
NULL
};
const double *s;
- s_skiplist__fact *skiplist;
+ s_skiplist__fact skiplist;
const double spacing[] = {2.0, 2.4, 3.0, 0.0};
for (h = height; *h; h++) {
for (s = spacing; *s != 0.0; s++) {
- skiplist = SKIPLIST_INIT_ALLOCA__fact(*h, *s);
+ skiplist_init__fact(&skiplist, *h, *s);
i = 0;
while (p[i]) {
fact_test_init_1(fact + i, p[i]);
- skiplist_insert__fact(skiplist, fact + i);
- TEST_ASSERT(skiplist_find__fact(skiplist, fact + i));
+ skiplist_insert__fact(&skiplist, fact + i);
+ TEST_ASSERT(skiplist_find__fact(&skiplist, fact + i));
i++;
}
- i = skiplist->length;
+ i = skiplist.length;
while (i--) {
- skiplist_remove__fact(skiplist, fact + i);
- TEST_ASSERT(! skiplist_find__fact(skiplist, fact + i));
+ skiplist_remove__fact(&skiplist, fact + i);
+ TEST_ASSERT(! skiplist_find__fact(&skiplist, fact + i));
fact_test_clean_1(fact + i);
}
- skiplist_clean__fact(skiplist);
+ skiplist_clean__fact(&skiplist);
}
}
}
@@ -171,7 +171,7 @@ void skiplist__fact_test_insert ()
NULL
};
s_fact fact[24];
- s_skiplist__fact *skiplist;
+ s_skiplist__fact skiplist;
i = 0;
while (p[i]) {
fact_test_init_1(fact + i, p[i]);
@@ -179,13 +179,13 @@ void skiplist__fact_test_insert ()
}
for (h = height; *h; h++) {
for (s = spacing; *s != 0.0; s++) {
- skiplist = SKIPLIST_INIT_ALLOCA__fact(*h, *s);
+ skiplist_init__fact(&skiplist, *h, *s);
i = 0;
while (p[i]) {
SKIPLIST__FACT_TEST_INSERT(fact + i, i + 1);
i++;
}
- skiplist_clean__fact(skiplist);
+ skiplist_clean__fact(&skiplist);
}
}
i = 0;
@@ -254,23 +254,23 @@ void skiplist__fact_test_remove ()
NULL
};
const double *s;
- s_skiplist__fact *skiplist;
+ s_skiplist__fact skiplist;
const double spacing[] = {2.0, 2.4, 3.0, 0.0};
for (h = height; *h; h++) {
for (s = spacing; *s != 0.0; s++) {
- skiplist = SKIPLIST_INIT_ALLOCA__fact(*h, *s);
+ skiplist_init__fact(&skiplist, *h, *s);
i = 0;
while (p[i]) {
fact_test_init_1(fact + i, p[i]);
- skiplist_insert__fact(skiplist, fact + i);
+ skiplist_insert__fact(&skiplist, fact + i);
i++;
}
- i = skiplist->length;
+ i = skiplist.length;
while (i--) {
SKIPLIST__FACT_TEST_REMOVE(fact + i, i);
fact_test_clean_1(fact + i);
}
- skiplist_clean__fact(skiplist);
+ skiplist_clean__fact(&skiplist);
}
}
}