From 2c63c56e0eb417b44449c235f9d4f46cbe4fb94a Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Tue, 15 Jul 2025 23:48:07 +0900 Subject: [PATCH] fix for old systems --- lib/std-cut.c | 11 ----------- t/err.sh | 20 ++++++++++++++++---- t/t-008.c | 5 +++-- t/t-009.c | 10 ++++++---- 4 files changed, 25 insertions(+), 21 deletions(-) diff --git a/lib/std-cut.c b/lib/std-cut.c index fb0acd6b..5c91215d 100644 --- a/lib/std-cut.c +++ b/lib/std-cut.c @@ -26,14 +26,6 @@ #include "hawk-prv.h" #include "hawk-std.h" -#if 0 -struct xtn_t -{ - const hawk_ooch_t* infile; - const hawk_ooch_t* outfile; -}; -#else - typedef struct xtn_in_t xtn_in_t; struct xtn_in_t { @@ -70,9 +62,6 @@ struct xtn_t hawk_link_t* sio_names; }; -#endif - -typedef struct xtn_t xtn_t; #if defined(HAWK_HAVE_INLINE) static HAWK_INLINE xtn_t* GET_XTN(hawk_cut_t* cut) { return (xtn_t*)((hawk_uint8_t*)hawk_cut_getxtn(cut) - HAWK_SIZEOF(xtn_t)); } diff --git a/t/err.sh b/t/err.sh index b98486c4..ee0205ae 100644 --- a/t/err.sh +++ b/t/err.sh @@ -3,6 +3,12 @@ for i in $@; do :; done script="$i" +escape_regex() { + local str="$1" + ## escape [, ], {, (, \, $, *, . ^, ), } + printf '%s\n' "$str" | sed -r -e 's/[][{(\$*.^)}]/\\&/g' +} + run_partfile() { l_cmd=""; l_nargs=$# @@ -21,7 +27,9 @@ run_partfile() { l_partfile="$1" l_cmd="$l_cmd $l_partfile" - l_expected_errinfo=$(grep -n -o -E "##ERROR: .+" "$l_partfile" 2>/dev/null) + ## old greps don't support -o. use sed to mimic it. + ##l_expected_errinfo=$(grep -n -o -E "##ERROR: .+" "$l_partfile" 2>/dev/null) + l_expected_errinfo=$(grep -n -E "##ERROR: .+" "$l_partfile" 2>/dev/null | sed -r -n 's/^([0-9]*):.*(##ERROR: .*)/\1:\2/p') [ -z "$l_expected_errinfo" ] && { echo "ERROR: INVALID TESTER - $l_script($l_partno) contains no ERROR information" return 1 @@ -33,8 +41,9 @@ run_partfile() { l_expected_errmsg=$(echo $l_expected_errinfo | cut -c${l_xlen}-) l_output=`$l_cmd 2>&1` ## the regular expression is not escaped properly. the error information must not - ## include specifial regex characters to avoid problems. - echo "$l_output" | grep -E "ERROR: .+ LINE ${l_expected_errline} .+ FILE ${l_partfile} - ${l_expected_errmsg}" >/dev/null 2>&1 || { + ## include special regex characters to avoid problems. + l_expected_errmsg_esc=$(escape_regex "${l_expected_errmsg}") + echo "$l_output" | grep -E "ERROR: .+ LINE ${l_expected_errline} .+ FILE ${l_partfile} - ${l_expected_errmsg_esc}" >/dev/null 2>&1 || { echo "ERROR: error not raised at line $l_expected_errline - $l_script($l_partno) - $l_output" return 1 } @@ -45,7 +54,10 @@ run_partfile() { ever_failed=0 -partfile=`mktemp` +## [NOTE] +## some old mktemp(e.g mktemp 1.5 on rhel 2.1) always required the template. +## these days, newer ones don't need it. +partfile=`mktemp tmp.XXXXXXXXXX` partno=0 partlines=0 > "$partfile" diff --git a/t/t-008.c b/t/t-008.c index a30ccc7c..ad7fbb35 100644 --- a/t/t-008.c +++ b/t/t-008.c @@ -26,6 +26,7 @@ int main(int argc, char* argv[]) clock_t start_time, end_time; double malloc_time = 0.0, free_time = 0.0; void **ptr_array; + size_t i; if (argc >= 3) { @@ -46,7 +47,7 @@ int main(int argc, char* argv[]) } start_time = clock(); - for (size_t i = 0; i < num_iterations; ++i) { + for (i = 0; i < num_iterations; ++i) { size_t size = random_size(max_alloc_size); /*ptr_array[i] = malloc(size);*/ ptr_array[i] = HAWK_MMGR_ALLOC(&xma_mmgr, size); @@ -64,7 +65,7 @@ int main(int argc, char* argv[]) malloc_time = (double)(end_time - start_time) / CLOCKS_PER_SEC; start_time = clock(); - for (size_t i = 0; i < num_iterations; ++i) { + for (i = 0; i < num_iterations; ++i) { /*free(ptr_array[i]);*/ HAWK_MMGR_FREE(&xma_mmgr, ptr_array[i]); } diff --git a/t/t-009.c b/t/t-009.c index 02761c4c..69c4a4d0 100644 --- a/t/t-009.c +++ b/t/t-009.c @@ -108,6 +108,7 @@ int main(int argc, char* argv[]) Allocation* allocations; /* pool of active allocations */ size_t num_active = 0; + size_t i; clock_t start_time, end_time; double malloc_time = 0.0, free_time = 0.0; @@ -144,7 +145,7 @@ int main(int argc, char* argv[]) srand((unsigned int)time(NULL)); start_time = clock(); - for (size_t i = 0; i < num_iterations; ++i) + for (i = 0; i < num_iterations; ++i) { int do_alloc = (num_active == 0) || (rand() % 2 == 0 && num_active < max_alloc_active); @@ -163,13 +164,14 @@ int main(int argc, char* argv[]) ++num_active; } else { /* free a random active allocation */ + clock_t t1, t2; size_t index = rand() % num_active; void *ptr_to_free = allocations[index].ptr; - clock_t t1 = clock(); + t1 = clock(); /*free(ptr_to_free); */ HAWK_MMGR_FREE(&xma_mmgr, ptr_to_free); - clock_t t2 = clock(); + t2 = clock(); free_time += (double)(t2 - t1) / CLOCKS_PER_SEC; /* replace with last active allocation */ @@ -182,7 +184,7 @@ int main(int argc, char* argv[]) /* hawk_xma_dump(xma_mmgr.ctx, print_xma, HAWK_NULL); */ /* Free remaining allocations */ - for (size_t i = 0; i < num_active; ++i) { + for (i = 0; i < num_active; ++i) { /* free(allocations[i].ptr); */ HAWK_MMGR_FREE(&xma_mmgr, allocations[i].ptr); }