Skip to content

Commit

Permalink
Get rid of the CB_COPY macro ##refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
MewtR committed Nov 30, 2024
1 parent 4b2234e commit 4d9d7e2
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 31 deletions.
21 changes: 1 addition & 20 deletions libr/core/libs.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,7 @@
return r_ ## x ## _plugin_remove (core->y, hand); \
}

// TODO: deprecate this
#define CB_COPY(x, y) \
static int __lib_ ## x ## _cb (RLibPlugin *pl, void *user, void *data) { \
struct r_ ## x ## _plugin_t *hand = (struct r_ ## x ## _plugin_t *)data; \
struct r_ ## x ## _plugin_t *instance; \
RCore *core = (RCore *)user; \
instance = R_NEW (struct r_ ## x ## _plugin_t); \
memcpy (instance, hand, sizeof (struct r_ ## x ## _plugin_t)); \
pl->name = strdup (hand->meta.name); \
r_ ## x ## _plugin_add (core->y, instance); \
return true; \
} \
static int __lib_ ## x ## _dt (RLibPlugin *pl, void *user, void *data) { \
struct r_ ## x ## _plugin_t *hand = (struct r_ ## x ## _plugin_t *)data; \
RCore *core = (RCore *)user; \
free (pl->name); \
return r_ ## x ## _plugin_remove (core->y, hand); \
}

CB_COPY (io, io)
CB (io, io)
CB (core, rcmd)
CB (debug, dbg)
CB (bp, dbg->bp)
Expand Down
13 changes: 2 additions & 11 deletions libr/io/io_plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,16 @@ R_API bool r_io_plugin_remove(RIO *io, RIOPlugin *plugin) {
}

R_API bool r_io_plugin_init(RIO *io) {
RIOPlugin *static_plugin;
int i;
if (!io) {
return false;
}
io->plugins = ls_newf (free);
io->plugins = ls_newf (NULL); // fine to use NULL here?
for (i = 0; io_static_plugins[i]; i++) {
if (!io_static_plugins[i]->meta.name) {
continue;
}
static_plugin = R_NEW0 (RIOPlugin);
if (!static_plugin) {
return false;
}
memcpy (static_plugin, io_static_plugins[i], sizeof (RIOPlugin));
if (!r_io_plugin_add (io, static_plugin)) {
free (static_plugin);
return false;
}
r_io_plugin_add (io, io_static_plugins[i]);
}
return true;
}
Expand Down

0 comments on commit 4d9d7e2

Please sign in to comment.