mirror of
https://github.com/radareorg/radare2.git
synced 2024-11-24 13:49:50 +00:00
Support wcu command for new io cache ##io
This commit is contained in:
parent
bc96eae13c
commit
80197aa2ac
@ -1366,11 +1366,25 @@ static void cmd_wcf(RCore *core, const char *dfn) {
|
||||
}
|
||||
|
||||
static void wcu(RCore *core) {
|
||||
#if USE_NEW_IO_CACHE_API
|
||||
R_LOG_WARN ("wcu not implemented for the new io-cache-api");
|
||||
#else
|
||||
void **iter;
|
||||
RIO *io = core->io;
|
||||
#if USE_NEW_IO_CACHE_API
|
||||
r_pvector_foreach_prev (io->cache->vec, iter) {
|
||||
RIOCacheItem *c = *iter;
|
||||
int cached = io->cached;
|
||||
io->cached = 0;
|
||||
r_io_write_at (io, r_itv_begin (c->itv), c->odata, r_itv_size (c->itv));
|
||||
c->written = false;
|
||||
io->cached = cached;
|
||||
r_pvector_remove_data (io->cache->vec, c);
|
||||
RPVectorFree free_elem = io->cache->vec->v.free_user;
|
||||
if (c->tree_itv) {
|
||||
r_crbtree_delete (io->cache->tree, c, io->cache->ci_cmp_cb, NULL);
|
||||
}
|
||||
free_elem (c);
|
||||
break;
|
||||
}
|
||||
#else
|
||||
r_pvector_foreach_prev (&io->cache, iter) {
|
||||
RIOCache *c = *iter;
|
||||
int cached = io->cached;
|
||||
|
@ -111,6 +111,7 @@ typedef struct r_io_undo_w_t {
|
||||
typedef struct r_io_cache_t {
|
||||
RPVector *vec;
|
||||
RRBTree *tree;
|
||||
RRBComparator ci_cmp_cb;
|
||||
} RIOCache;
|
||||
#endif
|
||||
|
||||
|
@ -251,6 +251,8 @@ R_API bool r_io_cache_read(RIO *io, ut64 addr, ut8 *buf, int len) {
|
||||
#else
|
||||
// USE_NEW_IO_CACHE_API
|
||||
|
||||
static int _ci_start_cmp_cb(void *incoming, void *in, void *user);
|
||||
|
||||
R_API RIOCacheItem * _io_cache_item_new(RInterval *itv) {
|
||||
RIOCacheItem *ci = R_NEW0 (RIOCacheItem);
|
||||
if (!ci) {
|
||||
@ -299,6 +301,7 @@ R_API void r_io_cache_init(RIO *io) {
|
||||
io->cache->tree = r_crbtree_new (NULL);
|
||||
io->cache->vec = r_pvector_new ((RPVectorFree)_io_cache_item_free);
|
||||
}
|
||||
io->cache->ci_cmp_cb = _ci_start_cmp_cb;
|
||||
io->cached = 0;
|
||||
}
|
||||
|
||||
@ -661,6 +664,7 @@ R_API RIOCache *r_io_cache_clone(RIO *io) {
|
||||
RIOCache *clone = R_NEW (RIOCache);
|
||||
clone->tree = r_crbtree_new (NULL);
|
||||
clone->vec = r_pvector_new ((RPVectorFree)_io_cache_item_free);
|
||||
clone->ci_cmp_cb = _ci_start_cmp_cb;
|
||||
void **iter;
|
||||
r_pvector_foreach (io->cache->vec, iter) {
|
||||
RIOCacheItem *ci = _clone_ci ((RIOCacheItem *)*iter);
|
||||
|
@ -336,6 +336,24 @@ idx=2 addr=0x00000006 size=3 000000 -> 909090 (written)
|
||||
EOF
|
||||
RUN
|
||||
|
||||
NAME=wcu should undo last change
|
||||
FILE=malloc://512
|
||||
CMDS=<<EOF
|
||||
e io.cache=true
|
||||
wx 11
|
||||
s+ 1
|
||||
wx 22
|
||||
s+ 1
|
||||
wx 33
|
||||
wcu
|
||||
wc
|
||||
EOF
|
||||
EXPECT=<<EOF
|
||||
idx=0 addr=0x00000000 size=1 00 -> 11 (not written)
|
||||
idx=1 addr=0x00000001 size=1 00 -> 22 (not written)
|
||||
EOF
|
||||
RUN
|
||||
|
||||
NAME=wcf should commit all the changes to a file
|
||||
FILE=bins/lua/hello.lua
|
||||
CMDS=<<EOF
|
||||
|
Loading…
Reference in New Issue
Block a user