From a6f51ee3faf37bfcb759b96ee76c85c490395b48 Mon Sep 17 00:00:00 2001 From: Mitya Selivanov Date: Fri, 1 Mar 2024 00:53:19 +0100 Subject: Remove unnecessary macro --- source/kit/input_buffer.c | 4 +-- source/kit/input_buffer.h | 10 ++---- source/kit/input_stream.h | 6 ---- source/kit/xml.c | 20 +++++------- source/tests/input_buffer.test.c | 44 +++++++++++++-------------- source/tests/input_stream.test.c | 4 +-- source/tests/xml.test.c | 66 ++++++++++++++++++++++------------------ 7 files changed, 73 insertions(+), 81 deletions(-) (limited to 'source') diff --git a/source/kit/input_buffer.c b/source/kit/input_buffer.c index 59298c8..1f3e274 100644 --- a/source/kit/input_buffer.c +++ b/source/kit/input_buffer.c @@ -32,7 +32,7 @@ static s32 kit_buf_adjust_(kit_input_buffer_t *buf, i64 size) { return KIT_OK; } -kit_input_buffer_t kit_ib_wrap(is_handle_t upstream, +kit_input_buffer_t kit_ib_init(is_handle_t upstream, kit_allocator_t *alloc) { kit_input_buffer_t buf; memset(&buf, 0, sizeof buf); @@ -118,7 +118,7 @@ kit_ib_token_t kit_ib_read(kit_ib_token_t tok, i64 size) { } else { \ DA_INIT(cache_dynamic, data.size, tok.buffer->data.alloc); \ if (cache_dynamic.size != data.size) { \ - (res_).status |= KIT_ERROR_OUT_OF_MEMORY; \ + (res_).status |= KIT_ERROR_OUT_OF_MEMORY; \ return (res_); \ } \ memcpy(cache_dynamic.values, data.values, data.size); \ diff --git a/source/kit/input_buffer.h b/source/kit/input_buffer.h index 4320ee7..c01b386 100644 --- a/source/kit/input_buffer.h +++ b/source/kit/input_buffer.h @@ -22,7 +22,7 @@ typedef struct { typedef b8 (*kit_ib_read_condition_fn)(kit_str_t data, void *context); -kit_input_buffer_t kit_ib_wrap(kit_is_handle_t upstream, +kit_input_buffer_t kit_ib_init(kit_is_handle_t upstream, kit_allocator_t *alloc); void kit_ib_destroy(kit_input_buffer_t *buf); @@ -45,12 +45,6 @@ kit_ib_token_t kit_ib_while(kit_ib_token_t buf, kit_ib_read_condition_fn condition, void *context); -#define KIT_IB_SKIP(buf_, proc_, ...) \ - do { \ - kit_ib_token_t temp_buf_ = (buf_); \ - (buf_) = proc_((buf_), __VA_ARGS__); \ - } while (0) - #ifdef __cplusplus } #endif @@ -58,7 +52,7 @@ kit_ib_token_t kit_ib_while(kit_ib_token_t buf, #define input_buffer_t kit_input_buffer_t #define ib_token_t kit_ib_token_t #define ib_read_condition_fn kit_ib_read_condition_fn -#define ib_wrap kit_ib_wrap +#define ib_init kit_ib_init #define ib_destroy kit_ib_destroy #define ib_token kit_ib_token #define ib_str kit_ib_str diff --git a/source/kit/input_stream.h b/source/kit/input_stream.h index 51a7520..3442ee4 100644 --- a/source/kit/input_stream.h +++ b/source/kit/input_stream.h @@ -24,10 +24,6 @@ kit_is_handle_t kit_is_wrap_file(FILE *f, kit_allocator_t *alloc); void kit_is_destroy(kit_is_handle_t in); -#define KIT_IS_WRAP_STRING(string) kit_is_wrap_string((string), NULL) - -#define KIT_IS_WRAP_FILE(f) kit_is_wrap_file((f), NULL) - #define KIT_IS_READ(in, destination) \ (in).read((in).state, (destination)) @@ -40,8 +36,6 @@ void kit_is_destroy(kit_is_handle_t in); #define is_wrap_string kit_is_wrap_string #define is_wrap_file kit_is_wrap_file #define is_destroy kit_is_destroy -#define IS_WRAP_STRING KIT_IS_WRAP_STRING -#define IS_WRAP_FILE KIT_IS_WRAP_FILE #define IS_READ KIT_IS_READ #endif diff --git a/source/kit/xml.c b/source/kit/xml.c index 0d8378c..f3cd18f 100644 --- a/source/kit/xml.c +++ b/source/kit/xml.c @@ -31,7 +31,8 @@ static s32 kit_xml_alloc_and_unescape_(str_builder_t *dst, str_t str, dst->values[dst->size++] = str.values[i]; else { i64 n = 1; - while (i + n < str.size && str.values[i + n] != ';') n++; + while (i + n < str.size && str.values[i + n] != ';') + n++; if (i + n >= str.size) { DA_DESTROY(*dst); return KIT_PARSING_FAILED; @@ -127,8 +128,7 @@ static ib_token_t kit_xml_parse_text_(ib_token_t begin, assert(dst->size == last.size); if (dst->size != last.size) - last.status |= KIT_ERROR_OUT_OF_MEMORY -; + last.status |= KIT_ERROR_OUT_OF_MEMORY; else if (last.size > 0) memcpy(dst->values, ib_str(last).values, last.size); @@ -148,8 +148,7 @@ static ib_token_t kit_xml_parse_text_(ib_token_t begin, assert(dst->size == n + next_text.size); if (dst->size != n + next_text.size) - next_text.status |= KIT_ERROR_OUT_OF_MEMORY - ; + next_text.status |= KIT_ERROR_OUT_OF_MEMORY; else memcpy(dst->values + n, ib_str(next_text).values, ib_str(next_text).size); @@ -248,8 +247,7 @@ static kit_xml_intermediate_t kit_xml_parse_buf_( assert(tag.properties.size == n + 1); if (tag.properties.size != n + 1) { - last.status |= KIT_ERROR_OUT_OF_MEMORY - ; + last.status |= KIT_ERROR_OUT_OF_MEMORY; DA_DESTROY(tag.properties); } else { last.status |= kit_xml_alloc_and_unescape_( @@ -306,8 +304,7 @@ static kit_xml_intermediate_t kit_xml_parse_buf_( assert(res.tags.size == n + 1); if (res.tags.size != n + 1) { - last.status |= KIT_ERROR_OUT_OF_MEMORY - ; + last.status |= KIT_ERROR_OUT_OF_MEMORY; xml_destroy(&tag); } else { last.status |= kit_xml_alloc_and_unescape_( @@ -339,7 +336,7 @@ static kit_xml_intermediate_t kit_xml_parse_buf_( kit_xml_parse_result_t kit_xml_parse(is_handle_t is, kit_allocator_t *alloc) { - input_buffer_t ib = ib_wrap(is, alloc); + input_buffer_t ib = ib_init(is, alloc); kit_xml_intermediate_t im = kit_xml_parse_buf_(ib_token(&ib), alloc); @@ -414,8 +411,7 @@ static s32 kit_xml_append_text_(str_builder_t *buf, xml_t *xml) { assert(buf->size == n + tail.size); if (buf->size != n + tail.size) - return KIT_ERROR_OUT_OF_MEMORY -; + return KIT_ERROR_OUT_OF_MEMORY; if (tail.size > 0) memcpy(buf->values + n, tail.values, tail.size); diff --git a/source/tests/input_buffer.test.c b/source/tests/input_buffer.test.c index 1ec1ad4..aba9a9b 100644 --- a/source/tests/input_buffer.test.c +++ b/source/tests/input_buffer.test.c @@ -5,8 +5,8 @@ TEST("input buffer read once") { str_t text = { .size = 3, .values = "foo" }; - is_handle_t in = IS_WRAP_STRING(text); - input_buffer_t buf = ib_wrap(in, NULL); + is_handle_t in = is_wrap_string(text, NULL); + input_buffer_t buf = ib_init(in, NULL); ib_token_t tok = ib_read(ib_token(&buf), 3); @@ -21,8 +21,8 @@ TEST("input buffer read once") { TEST("input buffer read again") { str_t text = { .size = 6, .values = "foobar" }; str_t foo = { .size = 3, .values = "foo" }; - is_handle_t in = IS_WRAP_STRING(text); - input_buffer_t buf = ib_wrap(in, NULL); + is_handle_t in = is_wrap_string(text, NULL); + input_buffer_t buf = ib_init(in, NULL); ib_token_t first = ib_read(ib_token(&buf), 3); ib_token_t second = ib_read(ib_token(&buf), 3); @@ -38,8 +38,8 @@ TEST("input buffer read twice") { str_t text = { .size = 6, .values = "foobar" }; str_t foo = { .size = 3, .values = "foo" }; str_t bar = { .size = 3, .values = "bar" }; - is_handle_t in = IS_WRAP_STRING(text); - input_buffer_t buf = ib_wrap(in, NULL); + is_handle_t in = is_wrap_string(text, NULL); + input_buffer_t buf = ib_init(in, NULL); ib_token_t first = ib_read(ib_token(&buf), 3); ib_token_t second = ib_read(first, 3); @@ -61,8 +61,8 @@ static b8 is_integer_(str_t const data, void *_) { TEST("input buffer read integer once") { str_t text = { .size = 9, .values = "31415 foo" }; str_t num = { .size = 5, .values = "31415" }; - is_handle_t in = IS_WRAP_STRING(text); - input_buffer_t buf = ib_wrap(in, NULL); + is_handle_t in = is_wrap_string(text, NULL); + input_buffer_t buf = ib_init(in, NULL); ib_token_t tok = ib_while(ib_token(&buf), is_integer_, NULL); @@ -78,8 +78,8 @@ TEST("input buffer read integer twice") { str_t text = { .size = 6, .values = "314 15" }; str_t num_0 = { .size = 3, .values = "314" }; str_t num_1 = { .size = 2, .values = "15" }; - is_handle_t in = IS_WRAP_STRING(text); - input_buffer_t buf = ib_wrap(in, NULL); + is_handle_t in = is_wrap_string(text, NULL); + input_buffer_t buf = ib_init(in, NULL); ib_token_t first = ib_while(ib_token(&buf), is_integer_, NULL); ib_token_t second = ib_read(first, 1); @@ -98,8 +98,8 @@ TEST("input buffer read integer twice") { TEST("input buffer any") { str_t text = SZ("01234bbdac"); str_t expect = SZ("01234"); - is_handle_t in = IS_WRAP_STRING(text); - input_buffer_t buf = ib_wrap(in, NULL); + is_handle_t in = is_wrap_string(text, NULL); + input_buffer_t buf = ib_init(in, NULL); ib_token_t tok = ib_any(ib_token(&buf), SZ("01234")); @@ -113,8 +113,8 @@ TEST("input buffer any") { TEST("input buffer none") { str_t text = SZ("01234bbdac"); str_t expect = SZ("01234"); - is_handle_t in = IS_WRAP_STRING(text); - input_buffer_t buf = ib_wrap(in, NULL); + is_handle_t in = is_wrap_string(text, NULL); + input_buffer_t buf = ib_init(in, NULL); ib_token_t tok = ib_none(ib_token(&buf), SZ("abcd")); @@ -128,8 +128,8 @@ TEST("input buffer none") { TEST("input buffer until") { str_t text = SZ("01234bbdac"); str_t expect = SZ("01234"); - is_handle_t in = IS_WRAP_STRING(text); - input_buffer_t buf = ib_wrap(in, NULL); + is_handle_t in = is_wrap_string(text, NULL); + input_buffer_t buf = ib_init(in, NULL); ib_token_t tok = ib_none(ib_token(&buf), SZ("bbdac")); @@ -143,8 +143,8 @@ TEST("input buffer until") { TEST("input buffer exact success") { str_t text = SZ("01234bbdac"); str_t expect = SZ("01234"); - is_handle_t in = IS_WRAP_STRING(text); - input_buffer_t buf = ib_wrap(in, NULL); + is_handle_t in = is_wrap_string(text, NULL); + input_buffer_t buf = ib_init(in, NULL); ib_token_t tok = ib_exact(ib_token(&buf), SZ("01234")); @@ -157,8 +157,8 @@ TEST("input buffer exact success") { TEST("input buffer exact fail") { str_t text = SZ("01234bbdac"); - is_handle_t in = IS_WRAP_STRING(text); - input_buffer_t buf = ib_wrap(in, NULL); + is_handle_t in = is_wrap_string(text, NULL); + input_buffer_t buf = ib_init(in, NULL); ib_token_t tok = ib_exact(ib_token(&buf), SZ("bbdac")); @@ -170,8 +170,8 @@ TEST("input buffer exact fail") { TEST("input buffer use after free") { str_t text = SZ("foobarfoobar"); - is_handle_t in = IS_WRAP_STRING(text); - input_buffer_t buf = ib_wrap(in, NULL); + is_handle_t in = is_wrap_string(text, NULL); + input_buffer_t buf = ib_init(in, NULL); ib_token_t first = ib_exact(ib_token(&buf), SZ("foobar")); ib_token_t second = ib_exact(first, ib_str(first)); diff --git a/source/tests/input_stream.test.c b/source/tests/input_stream.test.c index 25ef721..23a9a99 100644 --- a/source/tests/input_stream.test.c +++ b/source/tests/input_stream.test.c @@ -11,7 +11,7 @@ TEST("input stream wrap string") { str_t foo_ref = { .size = sizeof(foo) - 1, .values = foo }; str_t bar_ref = { .size = sizeof(bar) - 1, .values = bar }; - is_handle_t in = IS_WRAP_STRING(foo_ref); + is_handle_t in = is_wrap_string(foo_ref, NULL); char buf[4]; str_t buf_ref = { .size = sizeof(buf), .values = buf }; @@ -33,7 +33,7 @@ TEST("input stream wrap file") { f = fopen("_kit_temp", "rb"); - is_handle_t in = IS_WRAP_FILE(f); + is_handle_t in = is_wrap_file(f, NULL); REQUIRE_EQ(IS_READ(in, SZ(bar)), SZ(bar).size); REQUIRE(AR_EQUAL(SZ(foo), SZ(bar))); diff --git a/source/tests/xml.test.c b/source/tests/xml.test.c index 1534030..a31da8f 100644 --- a/source/tests/xml.test.c +++ b/source/tests/xml.test.c @@ -4,7 +4,7 @@ #include "../kit/test.h" TEST("xml parse tag") { - is_handle_t is = IS_WRAP_STRING(SZ(" ")); + is_handle_t is = is_wrap_string(SZ(" "), NULL); xml_parse_result_t res = xml_parse(is, NULL); REQUIRE_EQ(res.status, KIT_OK); @@ -19,7 +19,7 @@ TEST("xml parse tag") { } TEST("xml parse tag with dash") { - is_handle_t is = IS_WRAP_STRING(SZ(" ")); + is_handle_t is = is_wrap_string(SZ(" "), NULL); xml_parse_result_t res = xml_parse(is, NULL); REQUIRE_EQ(res.status, KIT_OK); @@ -34,7 +34,7 @@ TEST("xml parse tag with dash") { } TEST("xml parse tag not closed") { - is_handle_t is = IS_WRAP_STRING(SZ("")); + is_handle_t is = is_wrap_string(SZ(""), NULL); xml_parse_result_t res = xml_parse(is, NULL); REQUIRE_EQ(res.status, KIT_PARSING_FAILED); @@ -46,7 +46,7 @@ TEST("xml parse tag not closed") { } TEST("xml parse tag text") { - is_handle_t is = IS_WRAP_STRING(SZ(" bar ")); + is_handle_t is = is_wrap_string(SZ(" bar "), NULL); xml_parse_result_t res = xml_parse(is, NULL); REQUIRE_EQ(res.status, KIT_OK); @@ -62,7 +62,7 @@ TEST("xml parse tag text") { } TEST("xml parse empty tag") { - is_handle_t is = IS_WRAP_STRING(SZ("")); + is_handle_t is = is_wrap_string(SZ(""), NULL); xml_parse_result_t res = xml_parse(is, NULL); REQUIRE_EQ(res.status, KIT_OK); @@ -77,7 +77,7 @@ TEST("xml parse empty tag") { } TEST("xml parse tail") { - is_handle_t is = IS_WRAP_STRING(SZ(" bar")); + is_handle_t is = is_wrap_string(SZ(" bar"), NULL); xml_parse_result_t res = xml_parse(is, NULL); REQUIRE_EQ(res.status, KIT_OK); @@ -92,7 +92,7 @@ TEST("xml parse tail") { } TEST("xml parse empty tail") { - is_handle_t is = IS_WRAP_STRING(SZ(" bar")); + is_handle_t is = is_wrap_string(SZ(" bar"), NULL); xml_parse_result_t res = xml_parse(is, NULL); REQUIRE_EQ(res.status, KIT_OK); @@ -107,7 +107,7 @@ TEST("xml parse empty tail") { } TEST("xml parse property") { - is_handle_t is = IS_WRAP_STRING(SZ("")); + is_handle_t is = is_wrap_string(SZ(""), NULL); xml_parse_result_t res = xml_parse(is, NULL); REQUIRE_EQ(res.status, KIT_OK); @@ -126,7 +126,7 @@ TEST("xml parse property") { } TEST("xml parse empty property") { - is_handle_t is = IS_WRAP_STRING(SZ("")); + is_handle_t is = is_wrap_string(SZ(""), NULL); xml_parse_result_t res = xml_parse(is, NULL); REQUIRE_EQ(res.status, KIT_OK); @@ -145,7 +145,7 @@ TEST("xml parse empty property") { } TEST("xml parse child") { - is_handle_t is = IS_WRAP_STRING(SZ("")); + is_handle_t is = is_wrap_string(SZ(""), NULL); xml_parse_result_t res = xml_parse(is, NULL); REQUIRE_EQ(res.status, KIT_OK); @@ -162,7 +162,8 @@ TEST("xml parse child") { } TEST("xml parse child with text and tail") { - is_handle_t is = IS_WRAP_STRING(SZ("text tail")); + is_handle_t is = is_wrap_string(SZ("text tail"), + NULL); xml_parse_result_t res = xml_parse(is, NULL); REQUIRE_EQ(res.status, KIT_OK); @@ -182,7 +183,7 @@ TEST("xml parse child with text and tail") { } TEST("xml parse declaration") { - is_handle_t is = IS_WRAP_STRING(SZ("")); + is_handle_t is = is_wrap_string(SZ(""), NULL); xml_parse_result_t res = xml_parse(is, NULL); REQUIRE_EQ(res.status, KIT_OK); @@ -197,7 +198,7 @@ TEST("xml parse declaration") { } TEST("xml parse comment") { - is_handle_t is = IS_WRAP_STRING(SZ("")); + is_handle_t is = is_wrap_string(SZ(""), NULL); xml_parse_result_t res = xml_parse(is, NULL); REQUIRE_EQ(res.status, KIT_OK); @@ -212,7 +213,8 @@ TEST("xml parse comment") { } TEST("xml parse comment before text") { - is_handle_t is = IS_WRAP_STRING(SZ(" bar ")); + is_handle_t is = is_wrap_string(SZ(" bar "), + NULL); xml_parse_result_t res = xml_parse(is, NULL); REQUIRE_EQ(res.status, KIT_OK); @@ -227,7 +229,8 @@ TEST("xml parse comment before text") { } TEST("xml parse comment after text") { - is_handle_t is = IS_WRAP_STRING(SZ("foo ")); + is_handle_t is = is_wrap_string(SZ("foo "), + NULL); xml_parse_result_t res = xml_parse(is, NULL); REQUIRE_EQ(res.status, KIT_OK); @@ -242,8 +245,8 @@ TEST("xml parse comment after text") { } TEST("xml parse comment between text") { - is_handle_t is = IS_WRAP_STRING( - SZ("foo bar")); + is_handle_t is = is_wrap_string( + SZ("foo bar"), NULL); xml_parse_result_t res = xml_parse(is, NULL); REQUIRE_EQ(res.status, KIT_OK); @@ -258,7 +261,7 @@ TEST("xml parse comment between text") { } TEST("xml parse comment tail") { - is_handle_t is = IS_WRAP_STRING(SZ("")); + is_handle_t is = is_wrap_string(SZ(""), NULL); xml_parse_result_t res = xml_parse(is, NULL); REQUIRE_EQ(res.status, KIT_OK); @@ -273,7 +276,8 @@ TEST("xml parse comment tail") { } TEST("xml parse comment tail before text") { - is_handle_t is = IS_WRAP_STRING(SZ(" bar")); + is_handle_t is = is_wrap_string(SZ(" bar"), + NULL); xml_parse_result_t res = xml_parse(is, NULL); REQUIRE_EQ(res.status, KIT_OK); @@ -289,7 +293,8 @@ TEST("xml parse comment tail before text") { } TEST("xml parse comment tail after text") { - is_handle_t is = IS_WRAP_STRING(SZ(" bar ")); + is_handle_t is = is_wrap_string(SZ(" bar "), + NULL); xml_parse_result_t res = xml_parse(is, NULL); REQUIRE_EQ(res.status, KIT_OK); @@ -305,7 +310,8 @@ TEST("xml parse comment tail after text") { } TEST("xml parse comment tail between text") { - is_handle_t is = IS_WRAP_STRING(SZ("foo bar")); + is_handle_t is = is_wrap_string(SZ("foo bar"), + NULL); xml_parse_result_t res = xml_parse(is, NULL); REQUIRE_EQ(res.status, KIT_OK); @@ -321,7 +327,7 @@ TEST("xml parse comment tail between text") { } TEST("xml parse escaped text") { - is_handle_t is = IS_WRAP_STRING(SZ("<foo>")); + is_handle_t is = is_wrap_string(SZ("<foo>"), NULL); xml_parse_result_t res = xml_parse(is, NULL); REQUIRE_EQ(res.status, KIT_OK); @@ -336,7 +342,8 @@ TEST("xml parse escaped text") { } TEST("xml parse escaped quote property") { - is_handle_t is = IS_WRAP_STRING(SZ("")); + is_handle_t is = is_wrap_string(SZ(""), + NULL); xml_parse_result_t res = xml_parse(is, NULL); REQUIRE_EQ(res.status, KIT_OK); @@ -357,7 +364,8 @@ TEST("xml parse escaped quote property") { } TEST("xml parse escaped apostrophe property") { - is_handle_t is = IS_WRAP_STRING(SZ("")); + is_handle_t is = is_wrap_string(SZ(""), + NULL); xml_parse_result_t res = xml_parse(is, NULL); REQUIRE_EQ(res.status, KIT_OK); @@ -377,7 +385,7 @@ TEST("xml parse escaped apostrophe property") { } TEST("xml parse invalid escape") { - is_handle_t is = IS_WRAP_STRING(SZ("&foobar;")); + is_handle_t is = is_wrap_string(SZ("&foobar;"), NULL); xml_parse_result_t res = xml_parse(is, NULL); REQUIRE_EQ(res.status, KIT_PARSING_FAILED); @@ -389,8 +397,8 @@ TEST("xml parse invalid escape") { } TEST("xml full text") { - is_handle_t is = IS_WRAP_STRING( - SZ("foo text bar text tail")); + is_handle_t is = is_wrap_string( + SZ("foo text bar text tail"), NULL); xml_parse_result_t res = xml_parse(is, NULL); REQUIRE_EQ(res.status, KIT_OK); @@ -407,8 +415,8 @@ TEST("xml full text") { } TEST("xml property") { - is_handle_t is = IS_WRAP_STRING( - SZ("")); + is_handle_t is = is_wrap_string( + SZ(""), NULL); xml_parse_result_t res = xml_parse(is, NULL); REQUIRE_EQ(res.status, KIT_OK); -- cgit v1.2.3