Skip to content

Commit

Permalink
Introduce R_LIKELY macros and update sdb ##core
Browse files Browse the repository at this point in the history
* Bear in mind the gnuisms
  • Loading branch information
trufae committed May 21, 2022
1 parent 667eafd commit 6f6ea27
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 20 deletions.
8 changes: 4 additions & 4 deletions libr/cons/cons.c
Expand Up @@ -433,15 +433,15 @@ R_API bool r_cons_is_breaked(void) {
if (I->cb_break) {
I->cb_break (I->user);
}
if (I->timeout) {
if (R_UNLIKELY (I->timeout)) {
if (r_time_now_mono () > I->timeout) {
C->breaked = true;
C->was_breaked = true;
eprintf ("\nTimeout!\n");
I->timeout = 0;
}
}
if (!C->was_breaked) {
if (R_UNLIKELY (!C->was_breaked)) {
C->was_breaked = C->breaked;
}
return C && C->breaked;
Expand Down Expand Up @@ -477,9 +477,9 @@ R_API int r_cons_get_cur_line(void) {
if (isatty (fileno (stdin))) {
if (write (1, R_CONS_GET_CURSOR_POSITION, sizeof (R_CONS_GET_CURSOR_POSITION)) != -1) {
if (read (0, buf, sizeof (buf)) != sizeof (buf)) {
if (isdigit ((unsigned char)buf[2])) {
if (isdigit ((ut8)buf[2])) {
curline = (buf[2] - '0');
} if (isdigit ((unsigned char)buf[3])) {
} if (isdigit ((ut8)buf[3])) {
curline = curline * 10 + (buf[3] - '0');
}
}
Expand Down
6 changes: 3 additions & 3 deletions libr/core/anal_tp.c
Expand Up @@ -15,9 +15,9 @@ static bool anal_emul_init(RCore *core, RConfigHold *hc, RDebugTrace **dt, RAnal
core->dbg->trace = r_debug_trace_new ();
core->anal->esil->trace = r_anal_esil_trace_new (core->anal->esil);
r_config_hold (hc, "esil.romem", "dbg.trace", "esil.nonull", "dbg.follow", NULL);
r_config_set (core->config, "esil.romem", "true");
r_config_set (core->config, "dbg.trace", "true");
r_config_set (core->config, "esil.nonull", "true");
r_config_set_b (core->config, "esil.romem", true);
r_config_set_b (core->config, "dbg.trace", true);
r_config_set_b (core->config, "esil.nonull", true);
r_config_set_i (core->config, "dbg.follow", false);
const char *bp = r_reg_get_name (core->anal->reg, R_REG_NAME_BP);
const char *sp = r_reg_get_name (core->anal->reg, R_REG_NAME_SP);
Expand Down
4 changes: 2 additions & 2 deletions libr/core/cmd_anal.c
Expand Up @@ -7507,7 +7507,7 @@ static void cmd_anal_esil(RCore *core, const char *input, bool verbose) {
if (!esil->trace) {
break;
}
r_config_set_i (core->config, "dbg.trace", true);
r_config_set_b (core->config, "dbg.trace", true);
break;
case '-': // "aets-"
if (!esil) {
Expand All @@ -7520,7 +7520,7 @@ static void cmd_anal_esil(RCore *core, const char *input, bool verbose) {
}
r_anal_esil_trace_free (esil->trace);
esil->trace = NULL;
r_config_set_i (core->config, "dbg.trace", false);
r_config_set_b (core->config, "dbg.trace", false);
break;
default:
r_core_cmd_help (core, help_msg_aets);
Expand Down
8 changes: 4 additions & 4 deletions libr/debug/trace.c
Expand Up @@ -185,9 +185,9 @@ R_API void r_debug_trace_op(RDebug *dbg, RAnalOp *op) {
eprintf ("Run aeim to get dbg->anal->esil initialized\n");
}
}
}
if (oldpc != UT64_MAX) {
r_debug_trace_add (dbg, oldpc, op->size); //XXX review what this line really do
if (oldpc != UT64_MAX) {
r_debug_trace_add (dbg, oldpc, op->size); //XXX review what this line really do
}
}
oldpc = op->addr;
}
Expand Down Expand Up @@ -263,7 +263,7 @@ R_API void r_debug_trace_list(RDebug *dbg, int mode, ut64 offset) {
}

// XXX: find better name, make it public?
static int r_debug_trace_is_traceable(RDebug *dbg, ut64 addr) {
static bool r_debug_trace_is_traceable(RDebug *dbg, ut64 addr) {
if (dbg->trace->addresses) {
char addr_str[32];
snprintf (addr_str, sizeof (addr_str), "0x%08"PFMT64x, addr);
Expand Down
8 changes: 8 additions & 0 deletions libr/include/r_types_base.h
Expand Up @@ -27,6 +27,14 @@ extern "C" {
# define R_ALIGNED(x) __attribute__((aligned(x)))
#endif

#if defined(__GNUC__)
#define R_LIKELY(x) __builtin_expect((x),1)
#define R_UNLIKELY(x) __builtin_expect((x),0)
#else
#define R_LIKELY(x) (x)
#define R_UNLIKELY(x) (x)
#endif

#define R_IGNORE_RETURN(x) if ((x)) {;}

typedef R_ALIGNED(1) ut16 uut16;
Expand Down
12 changes: 7 additions & 5 deletions shlr/sdb/src/ht.inc
Expand Up @@ -201,12 +201,14 @@ static HT_(Kv) *reserve_kv(HtName_(Ht) *ht, const KEY_TYPE key, const int key_le
}
}

HT_(Kv) *newkvarr = (HT_(Kv)*)realloc (bt->arr, (bt->count + 1) * ht->opt.elem_size);
if (!newkvarr) {
return NULL;
if (bt->count + 1 >= bt->size) {
bt->size = (bt->count + 5) * 2;
HT_(Kv) *newkvarr = (HT_(Kv)*)realloc (bt->arr, (bt->size) * ht->opt.elem_size);
if (!newkvarr) {
return NULL;
}
bt->arr = newkvarr;
}

bt->arr = newkvarr;
bt->count++;
ht->count++;
return kv_at (ht, bt, bt->count - 1);
Expand Down
1 change: 1 addition & 0 deletions shlr/sdb/src/ht_inc.h
Expand Up @@ -73,6 +73,7 @@ typedef bool (*HT_(ForeachCallback))(void *user, const KEY_TYPE, const VALUE_TYP
typedef struct Ht_(bucket_t) {
HT_(Kv) *arr;
ut32 count;
ut32 size;
} HT_(Bucket);

/* Options contain all the settings of the hashtable */
Expand Down
4 changes: 2 additions & 2 deletions shlr/sdb/src/util.c
Expand Up @@ -21,7 +21,7 @@ struct timezone {
SDB_API int gettimeofday(struct timeval* p, struct timezone * tz) {
//ULARGE_INTEGER ul; // As specified on MSDN.
ut64 ul = 0;
static int tzflag = 0;
static bool tzflag = false;
FILETIME ft;
if (p) {
// Returns a 64-bit value representing the number of
Expand Down Expand Up @@ -49,7 +49,7 @@ SDB_API int gettimeofday(struct timeval* p, struct timezone * tz) {
if (tz) {
if (!tzflag) {
_tzset ();
tzflag++;
tzflag = true;
}
tz->tz_minuteswest = _timezone / 60;
tz->tz_dsttime = _daylight;
Expand Down

0 comments on commit 6f6ea27

Please sign in to comment.