Skip to content

Commit

Permalink
Update clang-format config
Browse files Browse the repository at this point in the history
  • Loading branch information
pelijah committed Apr 10, 2024
1 parent faa6491 commit 1f83498
Show file tree
Hide file tree
Showing 15 changed files with 85 additions and 90 deletions.
3 changes: 2 additions & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ AlignOperands: false
Cpp11BracedListStyle: false
ForEachMacros: ['rz_list_foreach', 'rz_list_foreach_safe', 'rz_pvector_foreach', 'rz_rbtree_foreach', 'rz_interval_tree_foreach', 'ls_foreach', 'rz_skiplist_foreach', 'graph_foreach_anode']
SortIncludes: false
RequiresClausePosition: SingleLine
RequiresClausePosition: SingleLine
TypenameMacros: ['HT_', 'Ht_', 'HtName_']
3 changes: 2 additions & 1 deletion librz/arch/dwarf_process.c
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,8 @@ static const char *map_dwarf_reg_to_riscv_reg(ut32 reg_num) {
}

#define KASE(_num, _reg) \
case _num: return #_reg;
case _num: \
return #_reg;

#include <arm/arm_dwarf_regnum_table.h>
#include <hexagon/hexagon_dwarf_reg_num_table.inc>
Expand Down
2 changes: 1 addition & 1 deletion librz/debug/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -1234,7 +1234,7 @@ RZ_API int rz_debug_continue_kill(RzDebug *dbg, int sig) {
#if DEBUGGER
/// if the plugin is not compiled link fails, so better do runtime linking
/// until this code gets fixed
static bool (*linux_attach_new_process)(RzDebug *dbg, int pid) = NULL;
static bool (*linux_attach_new_process)(RzDebug * dbg, int pid) = NULL;
if (!linux_attach_new_process) {
linux_attach_new_process = rz_sys_dlsym(NULL, "linux_attach_new_process");
}
Expand Down
75 changes: 34 additions & 41 deletions librz/include/rz_util/ht_inc.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@
#ifndef HT_STR_OPTION_DEFINED
#define HT_STR_OPTION_DEFINED
typedef enum {
HT_STR_DUP = 0, ///< String is copied when inserting into HT
HT_STR_OWN, ///< String ownership is transferred when inserting into HT
HT_STR_CONST ///< String is treated as constant and not copied when inserting into HT
HT_STR_DUP = 0, ///< String is copied when inserting into HT
HT_STR_OWN, ///< String ownership is transferred when inserting into HT
HT_STR_CONST ///< String is treated as constant and not copied when inserting into HT
} HtStrOption;
#endif

Expand All @@ -105,7 +105,7 @@ typedef int (*HT_(ListComparator))(const KEY_TYPE, const KEY_TYPE);
typedef bool (*HT_(ForeachCallback))(void *user, const KEY_TYPE, const VALUE_TYPE);

typedef struct Ht_(bucket_t) {
HT_(Kv) * arr;
HT_(Kv) *arr;
ut32 count;
}
HT_(Bucket);
Expand All @@ -114,66 +114,59 @@ HT_(Bucket);
* Options contain all the settings of the hashtable.
*/
typedef struct Ht_(options_t) {
HT_(ListComparator)
cmp; ///< RZ_NULLABLE. Function for comparing keys. Returns 0 if keys are equal.
///< Function is invoked only if == operator applied to keys returns false.
HT_(HashFunction)
hashfn; ///< RZ_NULLABLE. Function for hashing items in the hash table.
///< If NULL KEY_TO_HASH macro is used.
HT_(DupKey)
dupkey; ///< RZ_NULLABLE. Function for making a copy of key.
///< If NULL simple assignment operator is used.
HT_(DupValue)
dupvalue; ///< RZ_NULLABLE. Function for making a copy of value.
///< If NULL simple assignment operator is used.
HT_(CalcSizeK)
calcsizeK; ///< RZ_NULLABLE. Function to determine the key's size.
///< If NULL zero value is used as a size.
///< Key sizes are checked on equality during keys comparsion as a pre-check.
HT_(CalcSizeV)
calcsizeV; ///< RZ_NULLABLE. Function to determine the value's size.
///< If NULL zero value is used as a size.
///< Not required for common scenarios. Could be used in subclasses.
HT_(FiniKv)
finiKV; ///< RZ_NULLABLE. Function to clean up the key-value store.
HT_(ListComparator) cmp; ///< RZ_NULLABLE. Function for comparing keys.
///< Returns 0 if keys are equal.
///< Function is invoked only if == operator applied to keys returns false.
HT_(HashFunction) hashfn; ///< RZ_NULLABLE. Function for hashing items in the hash table.
///< If NULL KEY_TO_HASH macro is used.
HT_(DupKey) dupkey; ///< RZ_NULLABLE. Function for making a copy of key.
///< If NULL simple assignment operator is used.
HT_(DupValue) dupvalue; ///< RZ_NULLABLE. Function for making a copy of value.
///< If NULL simple assignment operator is used.
HT_(CalcSizeK) calcsizeK; ///< RZ_NULLABLE. Function to determine the key's size.
///< If NULL zero value is used as a size.
///< Key sizes are checked on equality during keys comparsion as a pre-check.
HT_(CalcSizeV) calcsizeV; ///< RZ_NULLABLE. Function to determine the value's size.
///< If NULL zero value is used as a size.
///< Not required for common scenarios. Could be used in subclasses.
HT_(FiniKv) finiKV; ///< RZ_NULLABLE. Function to clean up the key-value store.
void *finiKV_user; ///< RZ_NULLABLE. User data which is passed into finiKV.
size_t elem_size; ///< Size of each HtKv element (useful for subclassing like SdbKv).
///< Zero value means to use default size of HtKv.
///< Zero value means to use default size of HtKv.
}
HT_(Options);

/* Ht is the hashtable structure */
typedef struct Ht_(t) {
ut32 size; ///< Size of the hash table in buckets.
ut32 count; ///< Number of stored elements.
HT_(Bucket) * table; ///< Actual table.
HT_(Bucket) *table; ///< Actual table.
ut32 prime_idx;
HT_(Options)
opt;
HT_(Options) opt;
}
HtName_(Ht);

// Create a new Ht with the provided Options
RZ_API RZ_OWN HtName_(Ht) * Ht_(new_opt)(RZ_NONNULL HT_(Options) * opt);
RZ_API RZ_OWN HtName_(Ht) *Ht_(new_opt)(RZ_NONNULL HT_(Options) *opt);
// Create a new Ht with the provided Options and initial size
RZ_API RZ_OWN HtName_(Ht) * Ht_(new_opt_size)(RZ_NONNULL HT_(Options) * opt, ut32 initial_size);
RZ_API RZ_OWN HtName_(Ht) *Ht_(new_opt_size)(RZ_NONNULL HT_(Options) *opt, ut32 initial_size);
// Destroy a hashtable and all of its entries.
RZ_API void Ht_(free)(RZ_NULLABLE HtName_(Ht) * ht);
RZ_API void Ht_(free)(RZ_NULLABLE HtName_(Ht) *ht);
// Insert a new Key-Value pair into the hashtable. If the key already exists, returns false.
RZ_API bool Ht_(insert)(RZ_NONNULL HtName_(Ht) * ht, const KEY_TYPE key, VALUE_TYPE value);
RZ_API bool Ht_(insert)(RZ_NONNULL HtName_(Ht) *ht, const KEY_TYPE key, VALUE_TYPE value);
// Insert a new Key-Value pair into the hashtable, or updates the value if the key already exists.
RZ_API bool Ht_(update)(RZ_NONNULL HtName_(Ht) * ht, const KEY_TYPE key, VALUE_TYPE value);
RZ_API bool Ht_(update)(RZ_NONNULL HtName_(Ht) *ht, const KEY_TYPE key, VALUE_TYPE value);
// Update the key of an element in the hashtable
RZ_API bool Ht_(update_key)(RZ_NONNULL HtName_(Ht) * ht, const KEY_TYPE old_key, const KEY_TYPE new_key);
RZ_API bool Ht_(update_key)(RZ_NONNULL HtName_(Ht) *ht, const KEY_TYPE old_key, const KEY_TYPE new_key);
// Delete a key from the hashtable.
RZ_API bool Ht_(delete)(RZ_NONNULL HtName_(Ht) * ht, const KEY_TYPE key);
RZ_API bool Ht_(delete)(RZ_NONNULL HtName_(Ht) *ht, const KEY_TYPE key);
// Find the value corresponding to the matching key.
RZ_API VALUE_TYPE Ht_(find)(RZ_NONNULL HtName_(Ht) * ht, const KEY_TYPE key, RZ_NULLABLE bool *found);
RZ_API VALUE_TYPE Ht_(find)(RZ_NONNULL HtName_(Ht) *ht, const KEY_TYPE key, RZ_NULLABLE bool *found);
// Iterates over all elements in the hashtable, calling the cb function on each Kv.
// If the cb returns false, the iteration is stopped.
// cb should not modify the hashtable.
// NOTE: cb can delete the current element, but it should be avoided
RZ_API void Ht_(foreach)(RZ_NONNULL HtName_(Ht) * ht, RZ_NONNULL HT_(ForeachCallback) cb, RZ_NULLABLE void *user);
RZ_API void Ht_(foreach)(RZ_NONNULL HtName_(Ht) *ht, RZ_NONNULL HT_(ForeachCallback) cb, RZ_NULLABLE void *user);

RZ_API RZ_BORROW HT_(Kv) * Ht_(find_kv)(RZ_NONNULL HtName_(Ht) * ht, const KEY_TYPE key, RZ_NULLABLE bool *found);
RZ_API bool Ht_(insert_kv)(RZ_NONNULL HtName_(Ht) * ht, RZ_NONNULL HT_(Kv) * kv, bool update);
RZ_API RZ_BORROW HT_(Kv) *Ht_(find_kv)(RZ_NONNULL HtName_(Ht) *ht, const KEY_TYPE key, RZ_NULLABLE bool *found);
RZ_API bool Ht_(insert_kv)(RZ_NONNULL HtName_(Ht) *ht, RZ_NONNULL HT_(Kv) *kv, bool update);
2 changes: 1 addition & 1 deletion librz/include/rz_util/ht_sp.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ extern "C" {
#define HT_TYPE 5
#include <rz_util/ht_inc.h>

RZ_API RZ_OWN HtName_(Ht) * Ht_(new)(HtStrOption key_opt, RZ_NULLABLE HT_(DupValue) dup_val, RZ_NULLABLE HT_(FreeValue) free_val);
RZ_API RZ_OWN HtName_(Ht) *Ht_(new)(HtStrOption key_opt, RZ_NULLABLE HT_(DupValue) dup_val, RZ_NULLABLE HT_(FreeValue) free_val);
#undef HT_TYPE

#ifdef __cplusplus
Expand Down
2 changes: 1 addition & 1 deletion librz/include/rz_util/ht_ss.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ extern "C" {
#define HT_TYPE 6
#include <rz_util/ht_inc.h>

RZ_API RZ_OWN HtName_(Ht) * Ht_(new)(HtStrOption key_opt, HtStrOption val_opt);
RZ_API RZ_OWN HtName_(Ht) *Ht_(new)(HtStrOption key_opt, HtStrOption val_opt);
#undef HT_TYPE

#ifdef __cplusplus
Expand Down
2 changes: 1 addition & 1 deletion librz/include/rz_util/ht_su.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ extern "C" {
#define HT_TYPE 7
#include <rz_util/ht_inc.h>

RZ_API RZ_OWN HtName_(Ht) * Ht_(new)(HtStrOption key_opt);
RZ_API RZ_OWN HtName_(Ht) *Ht_(new)(HtStrOption key_opt);
#undef HT_TYPE

#ifdef __cplusplus
Expand Down
4 changes: 2 additions & 2 deletions librz/include/rz_util/ht_up.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ extern "C" {
#define HT_TYPE 2
#include <rz_util/ht_inc.h>

RZ_API RZ_OWN HtName_(Ht) * Ht_(new)(RZ_NULLABLE HT_(DupValue) valdup, RZ_NULLABLE HT_(FreeValue) valfree);
RZ_API RZ_OWN HtName_(Ht) * Ht_(new_size)(ut32 initial_size, RZ_NULLABLE HT_(DupValue) valdup, RZ_NULLABLE HT_(FreeValue) valfree);
RZ_API RZ_OWN HtName_(Ht) *Ht_(new)(RZ_NULLABLE HT_(DupValue) valdup, RZ_NULLABLE HT_(FreeValue) valfree);
RZ_API RZ_OWN HtName_(Ht) *Ht_(new_size)(ut32 initial_size, RZ_NULLABLE HT_(DupValue) valdup, RZ_NULLABLE HT_(FreeValue) valfree);
#undef HT_TYPE

#ifdef __cplusplus
Expand Down
2 changes: 1 addition & 1 deletion librz/include/rz_util/ht_uu.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ extern "C" {
#define HT_TYPE 3
#include <rz_util/ht_inc.h>

RZ_API RZ_OWN HtName_(Ht) * Ht_(new)(void);
RZ_API RZ_OWN HtName_(Ht) *Ht_(new)(void);
#undef HT_TYPE

#ifdef __cplusplus
Expand Down
Loading

0 comments on commit 1f83498

Please sign in to comment.