From 6c665c609879c790d2d2d835ec7a38e5776d8a5c Mon Sep 17 00:00:00 2001 From: Riccardo Schirone Date: Mon, 4 Jul 2022 14:01:30 +0200 Subject: [PATCH] Use Rizin specific macros instead of the ones from SDB --- librz/analysis/p/analysis_v850.c | 2 +- librz/cons/input.c | 2 +- librz/core/agraph.c | 4 ++-- librz/diff/unified_diff.c | 4 ++-- librz/include/rz_types.h | 5 ++++- librz/include/rz_userconf.h.in | 1 + librz/reg/double.c | 2 +- meson.build | 1 + subprojects/rzheap/rz_jemalloc/internal/bitmap.h | 2 +- subprojects/rzheap/rz_jemalloc/internal/hash.h | 4 ++-- test/unit/minunit.h | 2 ++ 11 files changed, 18 insertions(+), 11 deletions(-) diff --git a/librz/analysis/p/analysis_v850.c b/librz/analysis/p/analysis_v850.c index 9dbdc94f66..35e111dd4f 100644 --- a/librz/analysis/p/analysis_v850.c +++ b/librz/analysis/p/analysis_v850.c @@ -176,7 +176,7 @@ static int v850_op(RzAnalysis *analysis, RzAnalysisOp *op, ut64 addr, const ut8 ut16 word1 = 0, word2 = 0; struct v850_cmd cmd; - if (len < 1 || (len > 0 && !memcmp(buf, "\xff\xff\xff\xff\xff\xff", R_MIN(len, 6)))) { + if (len < 1 || (len > 0 && !memcmp(buf, "\xff\xff\xff\xff\xff\xff", RZ_MIN(len, 6)))) { return -1; } diff --git a/librz/cons/input.c b/librz/cons/input.c index 2dd1bd5b09..1133e43b62 100644 --- a/librz/cons/input.c +++ b/librz/cons/input.c @@ -487,7 +487,7 @@ static int __cons_readchar_w32(ut32 usec) { char *tmp = rz_utf16_to_utf8_l(&irInBuf.Event.KeyEvent.uChar.UnicodeChar, 1); if (tmp) { int len = strlen(tmp); - memcpy(&ch, tmp, R_MIN(len, sizeof(ch))); + memcpy(&ch, tmp, RZ_MIN(len, sizeof(ch))); free(tmp); } } else { diff --git a/librz/core/agraph.c b/librz/core/agraph.c index fde7439a1a..cf0216d01b 100644 --- a/librz/core/agraph.c +++ b/librz/core/agraph.c @@ -3798,7 +3798,7 @@ RZ_API bool rz_agraph_del_node(const RzAGraph *g, const char *title) { return true; } -static bool user_node_cb(struct g_cb *user, const void *k UNUSED, const void *v) { +static bool user_node_cb(struct g_cb *user, RZ_UNUSED const void *k, const void *v) { RzANodeCallback cb = user->node_cb; void *user_data = user->data; RzANode *n = (RzANode *)v; @@ -3808,7 +3808,7 @@ static bool user_node_cb(struct g_cb *user, const void *k UNUSED, const void *v) return true; } -static bool user_edge_cb(struct g_cb *user, const void *k UNUSED, const void *v) { +static bool user_edge_cb(struct g_cb *user, RZ_UNUSED const void *k, const void *v) { RAEdgeCallback cb = user->edge_cb; RzAGraph *g = user->graph; void *user_data = user->data; diff --git a/librz/diff/unified_diff.c b/librz/diff/unified_diff.c index 34656ba826..06193faf61 100644 --- a/librz/diff/unified_diff.c +++ b/librz/diff/unified_diff.c @@ -182,13 +182,13 @@ static inline void diff_unified_lines_hl(RzDiff *diff, RzDiffOp *op, RzStrBuf *s if (len && len_b && (p[0] == p_b[0] || p[len - 1] == p_b[len_b - 1])) { // Get left bound. st32 left = 0; - for (; left < R_MIN(len, len_b) && p[left] == p_b[left]; left++) + for (; left < RZ_MIN(len, len_b) && p[left] == p_b[left]; left++) ; char_bounds[bounds_idx * 2] = left; // Get right bound (offset). "- left" chops off // the left portion that has already matched. st32 right = 0; - for (; right < R_MIN(len, len_b) - left && p[len - 1 - right] == p_b[len_b - 1 - right]; + for (; right < RZ_MIN(len, len_b) - left && p[len - 1 - right] == p_b[len_b - 1 - right]; right++) ; char_bounds[bounds_idx * 2 + 1] = right; diff --git a/librz/include/rz_types.h b/librz/include/rz_types.h index 22e2ea2d2b..46a918f5b0 100644 --- a/librz/include/rz_types.h +++ b/librz/include/rz_types.h @@ -10,6 +10,9 @@ #include #include #include +#if HAVE_HEADER_INTTYPES_H +#include +#endif // TODO: fix this to make it crosscompile-friendly: RZ_SYS_OSTYPE ? /* operating system */ @@ -345,7 +348,7 @@ static inline void *rz_new_copy(int size, void *data) { #if !(defined(__GNUC__) && __GNUC__ < 5) || defined(__clang__) #define rz_offsetof(type, member) offsetof(type, member) #else -#if __SDB_WINDOWS__ +#if __WINDOWS__ #define rz_offsetof(type, member) ((unsigned long)(ut64) & ((type *)0)->member) #else #define rz_offsetof(type, member) ((unsigned long)&((type *)0)->member) diff --git a/librz/include/rz_userconf.h.in b/librz/include/rz_userconf.h.in index cbeee3e31a..86221c576e 100644 --- a/librz/include/rz_userconf.h.in +++ b/librz/include/rz_userconf.h.in @@ -54,6 +54,7 @@ #define HAVE_HEADER_SYS_SHM_H @HAVE_HEADER_SYS_SHM_H@ #define HAVE_HEADER_SYS_IPC_H @HAVE_HEADER_SYS_IPC_H@ #define HAVE_HEADER_SYS_MMAN_H @HAVE_HEADER_SYS_MMAN_H@ +#define HAVE_HEADER_INTTYPES_H @HAVE_HEADER_INTTYPES_H@ #define RZ_IS_PORTABLE @IS_PORTABLE@ // clang-format on diff --git a/librz/reg/double.c b/librz/reg/double.c index 1483374460..6fc9fc67c8 100644 --- a/librz/reg/double.c +++ b/librz/reg/double.c @@ -4,7 +4,7 @@ #include #include -#if __SDB_WINDOWS__ +#if __WINDOWS__ #define CASTLDBL (double) #else #define CASTLDBL diff --git a/meson.build b/meson.build index 1981e46ff1..775e993fb4 100644 --- a/meson.build +++ b/meson.build @@ -485,6 +485,7 @@ foreach item : [ ['sys/shm.h', '', []], ['sys/ipc.h', '', []], ['sys/mman.h', '', []], + ['inttypes.h', '', []], ] hdr = item[0] ok = cc.has_header(hdr, prefix: item[1], dependencies: item[2]) diff --git a/subprojects/rzheap/rz_jemalloc/internal/bitmap.h b/subprojects/rzheap/rz_jemalloc/internal/bitmap.h index ea4050eccc..9a686b1fda 100644 --- a/subprojects/rzheap/rz_jemalloc/internal/bitmap.h +++ b/subprojects/rzheap/rz_jemalloc/internal/bitmap.h @@ -236,7 +236,7 @@ bitmap_unset(bitmap_t *bitmap, const bitmap_info_t *binfo, size_t bit) size_t goff; bitmap_t *gp; bitmap_t g; - UNUSED bool propagate; + RZ_UNUSED bool propagate; assert(bit < binfo->nbits); assert(bitmap_get(bitmap, binfo, bit)); diff --git a/subprojects/rzheap/rz_jemalloc/internal/hash.h b/subprojects/rzheap/rz_jemalloc/internal/hash.h index 8bd7f324c6..dfe9a86010 100644 --- a/subprojects/rzheap/rz_jemalloc/internal/hash.h +++ b/subprojects/rzheap/rz_jemalloc/internal/hash.h @@ -152,7 +152,7 @@ hash_x86_32(const void *key, int len, uint32_t seed) return (h1); } -UNUSED JEMALLOC_INLINE void +RZ_UNUSED JEMALLOC_INLINE void hash_x86_128(const void *key, const int len, uint32_t seed, uint64_t rz_out[2]) { @@ -254,7 +254,7 @@ hash_x86_128(const void *key, const int len, uint32_t seed, rz_out[1] = (((uint64_t) h4) << 32) | h3; } -UNUSED JEMALLOC_INLINE void +RZ_UNUSED JEMALLOC_INLINE void hash_x64_128(const void *key, const int len, const uint32_t seed, uint64_t rz_out[2]) { diff --git a/test/unit/minunit.h b/test/unit/minunit.h index 7135557ed4..9c000a0bed 100644 --- a/test/unit/minunit.h +++ b/test/unit/minunit.h @@ -10,6 +10,8 @@ #ifndef _MINUNIT_H_ #define _MINUNIT_H_ +#include + #if __WINDOWS__ #define TRED #define TGREEN