Skip to content

Commit

Permalink
Add r_core_bind_cons() (#10715)
Browse files Browse the repository at this point in the history
  • Loading branch information
thestr4ng3r committed Jul 12, 2018
1 parent 93d9120 commit d3a3940
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
2 changes: 2 additions & 0 deletions libr/core/cmd_cmp.c
Expand Up @@ -715,6 +715,7 @@ static int cmd_cmp(void *data, const char *input) {
if (!r_core_file_open (core2, file2, 0, 0LL)) {
eprintf ("Cannot open diff file '%s'\n", file2);
r_core_free (core2);
r_core_bind_cons (core);
return false;
}
// TODO: must replicate on core1 too
Expand All @@ -729,6 +730,7 @@ static int cmd_cmp(void *data, const char *input) {
/* exchange a segfault with a memleak */
core2->config = NULL;
r_core_free (core2);
r_core_bind_cons (core);
}
break;
case 'u': // "cu"
Expand Down
24 changes: 11 additions & 13 deletions libr/core/core.c
Expand Up @@ -2087,17 +2087,11 @@ R_API bool r_core_init(RCore *core) {
core->print->cons = core->cons;
r_cons_bind (&core->print->consbind);

// We save the old num, in order to restore it after free
core->old_num = core->cons->num;
core->cons->num = core->num;
// We save the old num ad user, in order to restore it after free
core->lang = r_lang_new ();
core->lang->cmd_str = (char *(*)(void *, const char *))r_core_cmd_str;
core->lang->cmdf = (int (*)(void *, const char *, ...))r_core_cmdf;
core->cons->cb_editor = (RConsEditorCallback)r_core_editor;
core->cons->cb_break = (RConsBreakCallback)r_core_break;
core->cons->cb_sleep_begin = (RConsSleepBeginCallback)r_core_sleep_begin;
core->cons->cb_sleep_end = (RConsSleepEndCallback)r_core_sleep_end;
core->cons->user = (void*)core;
r_core_bind_cons (core);
core->lang->cb_printf = r_cons_printf;
r_lang_define (core->lang, "RCore", "core", core);
r_lang_set_user_ptr (core->lang, core);
Expand Down Expand Up @@ -2208,6 +2202,15 @@ R_API bool r_core_init(RCore *core) {
return 0;
}

R_API void r_core_bind_cons(RCore *core) {
core->cons->num = core->num;
core->cons->cb_editor = (RConsEditorCallback)r_core_editor;
core->cons->cb_break = (RConsBreakCallback)r_core_break;
core->cons->cb_sleep_begin = (RConsSleepBeginCallback)r_core_sleep_begin;
core->cons->cb_sleep_end = (RConsSleepEndCallback)r_core_sleep_end;
core->cons->user = (void*)core;
}

R_API RCore *r_core_fini(RCore *c) {
if (!c) {
return NULL;
Expand All @@ -2228,11 +2231,6 @@ R_API RCore *r_core_fini(RCore *c) {
free (c->block);
r_core_autocomplete_free (c->autocomplete);

// Check if the old num is saved. If yes, we restore it.
if (c->cons && c->old_num) {
c->cons->num = c->old_num;
c->old_num = NULL;
}
r_list_free (c->undos);
r_num_free (c->num);
// TODO: sync or not? sdb_sync (c->sdb);
Expand Down
2 changes: 1 addition & 1 deletion libr/include/r_core.h
Expand Up @@ -183,7 +183,6 @@ typedef struct r_core_t {
RCoreFile *file;
RList *files;
RNum *num;
RNum *old_num;
RLib *lib;
RCmd *rcmd;
RCmdDescriptor root_cmd_descriptor;
Expand Down Expand Up @@ -278,6 +277,7 @@ R_API RBin *r_core_get_bin (RCore *core);
R_API RConfig *r_core_get_config (RCore *core);
R_API RAsmOp *r_core_disassemble (RCore *core, ut64 addr);
R_API bool r_core_init(RCore *core);
R_API void r_core_bind_cons(RCore *core); // to restore pointers in cons
R_API RCore *r_core_new(void);
R_API RCore *r_core_free(RCore *core);
R_API RCore *r_core_fini(RCore *c);
Expand Down

0 comments on commit d3a3940

Please sign in to comment.