Skip to content

Commit

Permalink
Fix build errors from conflict resolving.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rot127 committed May 18, 2024
1 parent 1db1687 commit 80a46ea
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 89 deletions.
2 changes: 1 addition & 1 deletion librz/bin/format/pe/pe_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ RzPVector /*<char *>*/ *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;
}

Expand Down
4 changes: 2 additions & 2 deletions librz/core/cmd/cmd_eval.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,12 @@ RZ_API RZ_OWN RzPVector /*<char *>*/ *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;
}

Expand Down
3 changes: 2 additions & 1 deletion librz/include/rz_util/ht_inc.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ typedef struct Ht_(iter_t) {
st64 ti; ///< Table index
ut64 bi; ///< Bucket index
HT_(Kv) *kv; ///< Current Key-Value-pair. Stop iteration if kv is NULL.
} HT_(Iter);
}
HT_(Iter);

// Create a new Ht with the provided Options
RZ_API RZ_OWN HtName_(Ht) *Ht_(new_opt)(RZ_NONNULL HT_(Options) *opt);
Expand Down
4 changes: 2 additions & 2 deletions librz/include/rz_util/rz_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ RZ_API RZ_OWN RzPVector /*<char *>*/ *rz_set_s_to_vector(RZ_NONNULL RzSetS *set)
/**
* \brief Foreach iterator over a RzSetS. The set elements can be accessed via \p it->kv.key.
*/
#define rz_set_s_foreach(s, it) ht_foreach(sp, s, it)
#define rz_set_s_foreach(s, it) ht_foreach (sp, s, it)
#define RzSetSIter HtSPIter

typedef HtUP RzSetU;
Expand All @@ -41,7 +41,7 @@ RZ_API ut32 rz_set_u_size(RZ_NULLABLE RzSetU *set);
/**
* \brief Foreach iterator over a RzSetU. The set elements can be accessed via \p it->kv.key.
*/
#define rz_set_u_foreach(s, it) ht_foreach(up, s, it)
#define rz_set_u_foreach(s, it) ht_foreach (up, s, it)
#define RzSetUIter HtUPIter

#ifdef __cplusplus
Expand Down
4 changes: 4 additions & 0 deletions librz/util/set.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ 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
*
Expand Down
2 changes: 1 addition & 1 deletion test/unit/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ if get_option('enable_tests')
'graph',
'hash',
'hex',
'ht',
'id_storage',
'idpool',
'idstorage',
Expand All @@ -80,7 +81,6 @@ if get_option('enable_tests')
'rz_test',
'sdb_array',
'sdb_diff',
'sdb_hash',
'sdb_sdb',
'sdb_util',
'serialize_analysis',
Expand Down
162 changes: 80 additions & 82 deletions test/unit/test_ht.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <rz_util/ht_sp.h>
#include <rz_util/ht_su.h>
#include <rz_util/ht_ss.h>
#include <rz_util/set.h>
#include <rz_util/rz_set.h>
#include <rz_util/rz_str.h>

typedef struct _test_struct {
Expand Down Expand Up @@ -607,7 +607,7 @@ bool test_ht_uu_foreach(void) {
HtUU *ht = ht_uu_new();
ut32 icnt = 0;
HtUUIter it;
ht_foreach(uu, ht, it) {
ht_foreach (uu, ht, it) {
icnt++;
}
mu_assert_eq(icnt, 0, "Wrong number of iterations");
Expand All @@ -617,23 +617,22 @@ bool test_ht_uu_foreach(void) {
ht_uu_insert(ht, 0x4040404, 0x4040404);
ht_uu_insert(ht, 0x5050505, 0x5050505);
icnt = 0;
ht_foreach(uu, ht, it) {
ht_foreach (uu, ht, it) {
icnt++;
mu_assert_true(
it.kv->value == 0x1010101 ||
it.kv->value == 0x2020202 ||
it.kv->value == 0x3030303 ||
it.kv->value == 0x4040404 ||
it.kv->value == 0x5050505,
"Value mismtach"
);
it.kv->value == 0x1010101 ||
it.kv->value == 0x2020202 ||
it.kv->value == 0x3030303 ||
it.kv->value == 0x4040404 ||
it.kv->value == 0x5050505,
"Value mismtach");
}
mu_assert_eq(icnt, 5, "Wrong number of iterations");
icnt = 0;
// Test write of value
ht_foreach(uu, ht, it) {
ht_foreach (uu, ht, it) {
icnt++;
if(it.kv->value == 0x1010101) {
if (it.kv->value == 0x1010101) {
it.kv->value = 0x0;
}
}
Expand All @@ -650,7 +649,7 @@ bool test_ht_ss_foreach(void) {
HtSS *ht = ht_ss_new(HT_STR_CONST, HT_STR_CONST);
ut32 icnt = 0;
HtSSIter it;
ht_foreach(ss, ht, it) {
ht_foreach (ss, ht, it) {
icnt++;
}
mu_assert_eq(icnt, 0, "Wrong number of iterations");
Expand All @@ -661,7 +660,7 @@ bool test_ht_ss_foreach(void) {
ht_ss_insert(ht, "0x4040404", "0x4040404");
ht_ss_insert(ht, "0x5050505", "0x5050505");
icnt = 0;
ht_foreach(ss, ht, it) {
ht_foreach (ss, ht, it) {
icnt++;
mu_assert_true(
RZ_STR_EQ(it.kv->value, "0x1010101") ||
Expand All @@ -674,7 +673,7 @@ bool test_ht_ss_foreach(void) {
mu_assert_eq(icnt, 5, "Wrong number of iterations");
icnt = 0;
// Test write of value
ht_foreach(ss, ht, it) {
ht_foreach (ss, ht, it) {
icnt++;
if (RZ_STR_EQ(it.kv->value, "0x1010101")) {
it.kv->value = "0x0";
Expand All @@ -690,122 +689,121 @@ 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;
}

Expand Down

0 comments on commit 80a46ea

Please sign in to comment.