Branch: refs/heads/master Author: Colomban Wendling ban@herbesfolles.org Committer: Colomban Wendling ban@herbesfolles.org Date: Sun, 07 Feb 2016 03:31:38 UTC Commit: a3ccd47da18f2b762ae71dbccee93c037126d80e https://github.com/geany/geany-plugins/commit/a3ccd47da18f2b762ae71dbccee93c...
Log Message: ----------- debugger: Add reference counting to frame objects
This will allow safe sharing of the frame objects later on.
Modified Paths: -------------- debugger/src/debug.c debugger/src/debug_module.c debugger/src/debug_module.h
Modified: debugger/src/debug.c 6 lines changed, 3 insertions(+), 3 deletions(-) =================================================================== @@ -640,7 +640,7 @@ static void on_debugger_run (void) if (stack) { remove_stack_markers(); - g_list_foreach(stack, (GFunc)frame_free, NULL); + g_list_foreach(stack, (GFunc)frame_unref, NULL); g_list_free(stack); stack = NULL;
@@ -799,7 +799,7 @@ static void on_debugger_exited (int code) if (stack) { remove_stack_markers(); - g_list_foreach(stack, (GFunc)frame_free, NULL); + g_list_foreach(stack, (GFunc)frame_unref, NULL); g_list_free(stack); stack = NULL; } @@ -1075,7 +1075,7 @@ void debug_destroy(void) if (stack) { remove_stack_markers(); - g_list_foreach(stack, (GFunc)frame_free, NULL); + g_list_foreach(stack, (GFunc)frame_unref, NULL); g_list_free(stack); stack = NULL; }
Modified: debugger/src/debug_module.c 28 lines changed, 15 insertions(+), 13 deletions(-) =================================================================== @@ -79,26 +79,28 @@ void variable_reset(variable *var) /* creates new frame */ frame* frame_new(void) { - frame *f = (frame*)malloc(sizeof(frame)); - memset((void*)f, 0, sizeof(frame)); + frame *f = g_malloc0(sizeof *f); + f->ref_count = 1; return f; }
-/* frees a frame */ -void frame_free(frame* f) +/* refs a frame */ +frame* frame_ref(frame* f) { - if (f->address) + f->ref_count++; + return f; +} + +/* unrefs a frame */ +void frame_unref(frame* f) +{ + if (f->ref_count > 1) + f->ref_count--; + else { g_free(f->address); - } - if (f->function) - { g_free(f->function); - } - if (f->file) - { g_free(f->file); + g_free(f); } - - g_free(f); }
Modified: debugger/src/debug_module.h 6 lines changed, 4 insertions(+), 2 deletions(-) =================================================================== @@ -79,6 +79,7 @@ typedef struct _variable {
/* type to hold information about a stack frame */ typedef struct _frame { + gint ref_count; gchar *address; gchar *function; gchar *file; @@ -170,7 +171,8 @@ variable* variable_new(const gchar *name, variable_type vt); variable* variable_new2(const gchar *name, const gchar *internal, variable_type vt); void variable_reset(variable *var);
-frame* frame_new(void); -void frame_free(frame* f); +frame* frame_new(void); +frame* frame_ref(frame* f); +void frame_unref(frame* f);
#endif /* guard */
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).