From a5d3972f6eff1ac9a3f7fbc0f359add75348f411 Mon Sep 17 00:00:00 2001 From: Rot127 Date: Sat, 18 May 2024 07:49:04 -0500 Subject: [PATCH] Fix build errors from conflict resolving. --- librz/bin/format/pe/pe_info.c | 2 +- librz/core/cmd/cmd_eval.c | 4 +- librz/util/set.c | 5 ++ test/unit/meson.build | 2 +- test/unit/test_ht.c | 134 +++++++++++++++++----------------- 5 files changed, 76 insertions(+), 71 deletions(-) diff --git a/librz/bin/format/pe/pe_info.c b/librz/bin/format/pe/pe_info.c index ee34d7d3419..f1b6dea3977 100644 --- a/librz/bin/format/pe/pe_info.c +++ b/librz/bin/format/pe/pe_info.c @@ -457,7 +457,7 @@ RzPVector /**/ *PE_(rz_bin_pe_get_libs)(RzBinPEObj *bin) { } } RzPVector *vec = rz_set_s_to_vector(libs); - set_s_free(libs); + rz_set_s_free(libs); return vec; } diff --git a/librz/core/cmd/cmd_eval.c b/librz/core/cmd/cmd_eval.c index eba19441809..d076a3007b7 100644 --- a/librz/core/cmd/cmd_eval.c +++ b/librz/core/cmd/cmd_eval.c @@ -129,12 +129,12 @@ RZ_API RZ_OWN RzPVector /**/ *rz_core_get_themes(RZ_NONNULL RzCore *core RzPVector *vec = rz_set_s_to_vector(themes); if (!vec) { - set_s_free(themes); + rz_set_s_free(themes); return NULL; } rz_pvector_push(vec, strdup("default")); rz_pvector_sort(vec, (RzPVectorComparator)compare_strings, NULL); - set_s_free(themes); + rz_set_s_free(themes); return vec; } diff --git a/librz/util/set.c b/librz/util/set.c index 373c3e9ddb5..282007b813b 100644 --- a/librz/util/set.c +++ b/librz/util/set.c @@ -42,6 +42,11 @@ static bool push_to_pvector(void *user, const char *k, RZ_UNUSED const void *v) return !!rz_pvector_push(vec, (void *)k); } + +RZ_API void rz_set_s_free(RZ_NULLABLE RzSetS *set) { + ht_sp_free((HtSP *)set); +} + /** * \brief Create a vector from elements of hash set \p set * diff --git a/test/unit/meson.build b/test/unit/meson.build index c5ca0883b74..3b56c68db7f 100644 --- a/test/unit/meson.build +++ b/test/unit/meson.build @@ -54,6 +54,7 @@ if get_option('enable_tests') 'graph', 'hash', 'hex', + 'ht', 'id_storage', 'idpool', 'idstorage', @@ -80,7 +81,6 @@ if get_option('enable_tests') 'rz_test', 'sdb_array', 'sdb_diff', - 'sdb_hash', 'sdb_sdb', 'sdb_util', 'serialize_analysis', diff --git a/test/unit/test_ht.c b/test/unit/test_ht.c index 578da446ab6..b0992e2eae3 100644 --- a/test/unit/test_ht.c +++ b/test/unit/test_ht.c @@ -10,7 +10,7 @@ #include #include #include -#include +#include #include typedef struct _test_struct { @@ -690,122 +690,122 @@ bool test_ht_ss_foreach(void) { } bool test_set_u(void) { - SetU *set_u = set_u_new(); - set_u_add(set_u, 0x5050505); - set_u_add(set_u, 0x5050505); - set_u_add(set_u, 0x6060606); - set_u_add(set_u, 0x7070707); - set_u_add(set_u, 0x7070707); - mu_assert_eq(set_u_size(set_u), 3, "Length wrong."); - mu_assert_true(set_u_contains(set_u, 0x5050505), "Value was not added."); - mu_assert_true(set_u_contains(set_u, 0x6060606), "Value was not added."); - mu_assert_true(set_u_contains(set_u, 0x7070707), "Value was not added."); - - set_u_delete(set_u, 0x7070707); - mu_assert_false(set_u_contains(set_u, 0x7070707), "Value was not deleted."); - mu_assert_eq(set_u_size(set_u), 2, "Length wrong."); + RzSetU *set_u = rz_set_u_new(); + rz_set_u_add(set_u, 0x5050505); + rz_set_u_add(set_u, 0x5050505); + rz_set_u_add(set_u, 0x6060606); + rz_set_u_add(set_u, 0x7070707); + rz_set_u_add(set_u, 0x7070707); + mu_assert_eq(rz_set_u_size(set_u), 3, "Length wrong."); + mu_assert_true(rz_set_u_contains(set_u, 0x5050505), "Value was not added."); + mu_assert_true(rz_set_u_contains(set_u, 0x6060606), "Value was not added."); + mu_assert_true(rz_set_u_contains(set_u, 0x7070707), "Value was not added."); + + rz_set_u_delete(set_u, 0x7070707); + mu_assert_false(rz_set_u_contains(set_u, 0x7070707), "Value was not deleted."); + mu_assert_eq(rz_set_u_size(set_u), 2, "Length wrong."); // Double delete - set_u_delete(set_u, 0x7070707); - mu_assert_eq(set_u_size(set_u), 2, "Length wrong."); + rz_set_u_delete(set_u, 0x7070707); + mu_assert_eq(rz_set_u_size(set_u), 2, "Length wrong."); size_t x = 0; - SetUIter it; - set_u_foreach (set_u, it) { + RzSetUIter it; + rz_set_u_foreach (set_u, it) { x++; bool matches = it.kv->key == 0x5050505 || it.kv->key == 0x6060606; mu_assert_true(matches, "Set contained ill-formed value."); } mu_assert_eq(x, 2, "Foreach hasn't iterated the correct number of times."); - set_u_delete(set_u, 0x6060606); - mu_assert_eq(set_u_size(set_u), 1, "Length wrong."); - set_u_delete(set_u, 0x5050505); - mu_assert_eq(set_u_size(set_u), 0, "Length wrong."); + rz_set_u_delete(set_u, 0x6060606); + mu_assert_eq(rz_set_u_size(set_u), 1, "Length wrong."); + rz_set_u_delete(set_u, 0x5050505); + mu_assert_eq(rz_set_u_size(set_u), 0, "Length wrong."); - set_u_foreach (set_u, it) { + rz_set_u_foreach (set_u, it) { mu_assert("Should not be reached.", false); } - set_u_add(set_u, 0x53e0); - set_u_add(set_u, 0x53bc); + rz_set_u_add(set_u, 0x53e0); + rz_set_u_add(set_u, 0x53bc); x = 0; - set_u_foreach (set_u, it) { + rz_set_u_foreach (set_u, it) { x++; } mu_assert_eq(x, 2, "Foreach hasn't iterated the correct number of times."); - set_u_delete(set_u, 0x53e0); - set_u_delete(set_u, 0x53bc); + rz_set_u_delete(set_u, 0x53e0); + rz_set_u_delete(set_u, 0x53bc); - set_u_add(set_u, 0); - set_u_add(set_u, 1); - set_u_add(set_u, 2); - set_u_add(set_u, 3); + rz_set_u_add(set_u, 0); + rz_set_u_add(set_u, 1); + rz_set_u_add(set_u, 2); + rz_set_u_add(set_u, 3); // Add an address as key which is far away from the heap addresses. - set_u_add(set_u, 100000000); - mu_assert_true(set_u_contains(set_u, 100000000), "Not contained."); + rz_set_u_add(set_u, 100000000); + mu_assert_true(rz_set_u_contains(set_u, 100000000), "Not contained."); mu_assert_eq(set_u->count, 5, "count"); - mu_assert_false(set_u_contains(set_u, 6), "should not be here."); + mu_assert_false(rz_set_u_contains(set_u, 6), "should not be here."); x = 0; - set_u_foreach (set_u, it) { + rz_set_u_foreach (set_u, it) { x++; } mu_assert_eq(x, 5, "Foreach hasn't iterated the correct number of times."); - set_u_free(set_u); + rz_set_u_free(set_u); mu_end; } bool test_set_s(void) { - SetS *set_s = set_s_new(HT_STR_CONST); - set_s_add(set_s, "0x5050505"); - set_s_add(set_s, "0x5050505"); - set_s_add(set_s, "0x6060606"); - set_s_add(set_s, "0x7070707"); - set_s_add(set_s, "0x7070707"); - mu_assert_eq(set_s_size(set_s), 3, "Length wrong."); - mu_assert_true(set_s_contains(set_s, "0x5050505"), "Value was not added."); - mu_assert_true(set_s_contains(set_s, "0x6060606"), "Value was not added."); - mu_assert_true(set_s_contains(set_s, "0x7070707"), "Value was not added."); - - set_s_delete(set_s, "0x7070707"); - mu_assert_false(set_s_contains(set_s, "0x7070707"), "Value was not deleted."); - mu_assert_eq(set_s_size(set_s), 2, "Length wrong."); + RzSetS *set_s = rz_set_s_new(HT_STR_CONST); + rz_set_s_add(set_s, "0x5050505"); + rz_set_s_add(set_s, "0x5050505"); + rz_set_s_add(set_s, "0x6060606"); + rz_set_s_add(set_s, "0x7070707"); + rz_set_s_add(set_s, "0x7070707"); + mu_assert_eq(rz_set_s_size(set_s), 3, "Length wrong."); + mu_assert_true(rz_set_s_contains(set_s, "0x5050505"), "Value was not added."); + mu_assert_true(rz_set_s_contains(set_s, "0x6060606"), "Value was not added."); + mu_assert_true(rz_set_s_contains(set_s, "0x7070707"), "Value was not added."); + + rz_set_s_delete(set_s, "0x7070707"); + mu_assert_false(rz_set_s_contains(set_s, "0x7070707"), "Value was not deleted."); + mu_assert_eq(rz_set_s_size(set_s), 2, "Length wrong."); // Double delete - set_s_delete(set_s, "0x7070707"); - mu_assert_eq(set_s_size(set_s), 2, "Length wrong."); + rz_set_s_delete(set_s, "0x7070707"); + mu_assert_eq(rz_set_s_size(set_s), 2, "Length wrong."); size_t x = 0; - SetSIter it; - set_s_foreach (set_s, it) { + RzSetSIter it; + rz_set_s_foreach (set_s, it) { x++; bool matches = RZ_STR_EQ(it.kv->key, "0x5050505") || RZ_STR_EQ(it.kv->key, "0x6060606"); mu_assert_true(matches, "Set contained ill-formed value."); } mu_assert_eq(x, 2, "Foreach hasn't iterated the correct number of times."); - set_s_delete(set_s, "0x6060606"); - mu_assert_eq(set_s_size(set_s), 1, "Length wrong."); - set_s_delete(set_s, "0x5050505"); - mu_assert_eq(set_s_size(set_s), 0, "Length wrong."); + rz_set_s_delete(set_s, "0x6060606"); + mu_assert_eq(rz_set_s_size(set_s), 1, "Length wrong."); + rz_set_s_delete(set_s, "0x5050505"); + mu_assert_eq(rz_set_s_size(set_s), 0, "Length wrong."); - set_s_foreach (set_s, it) { + rz_set_s_foreach (set_s, it) { mu_assert("Should not be reached.", false); } - set_s_add(set_s, "0x53e0"); - set_s_add(set_s, "0x53bc"); + rz_set_s_add(set_s, "0x53e0"); + rz_set_s_add(set_s, "0x53bc"); x = 0; - set_s_foreach (set_s, it) { + rz_set_s_foreach (set_s, it) { x++; } mu_assert_eq(x, 2, "Foreach hasn't iterated the correct number of times."); - set_s_delete(set_s, "0x53e0"); - set_s_delete(set_s, "0x53bc"); + rz_set_s_delete(set_s, "0x53e0"); + rz_set_s_delete(set_s, "0x53bc"); - set_s_free(set_s); + rz_set_s_free(set_s); mu_end; }