static void setHint (RAnal *a, const char *type, ut64 addr, const char *s, ut64 ptr) { int idx; char key[128], val[128], *nval = NULL; setf (key, "hint.0x%"PFMT64x, addr); idx = sdb_array_indexof (DB, key, type, 0); if (s) nval = sdb_encode ((const ut8*)s, -1); else nval = sdb_itoa (ptr, val, 16); if (idx != -1) { if (!s) nval = sdb_itoa (ptr, val, 16); sdb_array_set (DB, key, idx+1, nval, 0); } else { sdb_array_push (DB, key, nval, 0); sdb_array_push (DB, key, type, 0); } if (s) free (nval); }
bool test_sdb_array_push_pop(void) { Sdb *db = sdb_new (NULL, NULL, false); char *p; sdb_array_push (db, "foo", "foo", 0); sdb_array_push (db, "foo", "bar", 0); sdb_array_push (db, "foo", "cow", 0); mu_assert_streq (sdb_const_get (db, "foo", 0), "cow,bar,foo", "Not all items found"); p = sdb_array_pop (db, "foo", NULL); mu_assert_streq (p, "cow", "cow was not at the top"); p = sdb_array_pop (db, "foo", NULL); mu_assert_streq (p, "bar", "bar was not at the top"); p = sdb_array_pop (db, "foo", NULL); mu_assert_streq (p, "foo", "foo was not at the top"); p = sdb_array_pop (db, "foo", NULL); mu_assert_eq ((int)(size_t)p, (int)(size_t)NULL, "there shouldn't be any element in the array"); sdb_free (db); mu_end; }
int main(int argc, char **argv) { int i, N; if (argc>1) N = atoi (argv[1]); else N = 1000; Sdb *s = sdb_new (NULL, NULL, 0); for (i=0;i<N;i++) sdb_array_push (s, "key", "foo", 0); #if 1 if (N != sdb_alen (sdb_const_get (s, "key", 0))) { printf ("FAIL IN VERY PUSH\n"); return 1; } eprintf ("--%d\n", (int)strlen (sdb_const_get (s, "key", 0))); #endif for (i=0;i<N;i++) free (sdb_array_pop (s, "key", 0)); sdb_free (s); return 0; }
SDB_API int sdb_array_prepend_num(Sdb *s, const char *key, ut64 num, ut32 cas) { char buf[SDB_NUM_BUFSZ]; char *n = sdb_itoa (num, buf, SDB_NUM_BASE); return sdb_array_push (s, key, n, cas); }