From 0449deee271da392505ccd73f2b5db1896209c8f Mon Sep 17 00:00:00 2001 From: Michael Natterer Date: Tue, 14 Dec 2004 22:42:00 +0000 Subject: [PATCH] added "gint ref_count" to the PlugInProcFrame struct. Added new functions 2004-12-14 Michael Natterer * app/plug-in/plug-in-proc-frame.[ch]: added "gint ref_count" to the PlugInProcFrame struct. Added new functions plug_in_proc_frame_ref/unref(). (plug_in_proc_frame_new): set the ref_count to 1. * app/plug-in/plug-in.[ch] (plug_in_proc_frame_push): return the new proc_frame. (plug_in_proc_frame_pop): use unref() instead of free(). * app/plug-in/plug-in-run.c (plug_in_temp_run): ref the proc_frame while running its main loop. Removed the call to plug_in_proc_frame_pop(). * app/plug-in/plug-in-message.c (plug_in_handle_temp_proc_return): call plug_in_proc_frame_pop() immediately after plug_in_main_loop_quit() so the proc_frame goes away from the stack and can't be used accidentially if the core is too busy to return to the main loop before the next command arrives on the wire. Really fixes bug #161114 this time. --- ChangeLog | 24 ++++++++++++++++++++++++ app/plug-in/gimpplugin-message.c | 1 + app/plug-in/gimpplugin.c | 14 ++++++++------ app/plug-in/gimpplugin.h | 2 +- app/plug-in/gimppluginmanager-call.c | 15 ++++++++++----- app/plug-in/gimppluginmanager-run.c | 15 ++++++++++----- app/plug-in/gimppluginprocframe.c | 25 +++++++++++++++++++++++++ app/plug-in/gimppluginprocframe.h | 6 ++++++ app/plug-in/plug-in-message.c | 1 + app/plug-in/plug-in-proc-frame.c | 25 +++++++++++++++++++++++++ app/plug-in/plug-in-proc-frame.h | 6 ++++++ app/plug-in/plug-in-run.c | 15 ++++++++++----- app/plug-in/plug-in.c | 14 ++++++++------ app/plug-in/plug-in.h | 2 +- 14 files changed, 136 insertions(+), 29 deletions(-) diff --git a/ChangeLog b/ChangeLog index 811cdb3c0e..76aa411217 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,27 @@ +2004-12-14 Michael Natterer + + * app/plug-in/plug-in-proc-frame.[ch]: added "gint ref_count" to + the PlugInProcFrame struct. Added new functions + plug_in_proc_frame_ref/unref(). + + (plug_in_proc_frame_new): set the ref_count to 1. + + * app/plug-in/plug-in.[ch] (plug_in_proc_frame_push): return the + new proc_frame. + + (plug_in_proc_frame_pop): use unref() instead of free(). + + * app/plug-in/plug-in-run.c (plug_in_temp_run): ref the proc_frame + while running its main loop. Removed the call to + plug_in_proc_frame_pop(). + + * app/plug-in/plug-in-message.c (plug_in_handle_temp_proc_return): + call plug_in_proc_frame_pop() immediately after + plug_in_main_loop_quit() so the proc_frame goes away from the + stack and can't be used accidentially if the core is too busy to + return to the main loop before the next command arrives on the + wire. Really fixes bug #161114 this time. + 2004-12-14 Simon Budig * app/vectors/gimpstroke.[ch]: Changed the "gradient" parameter diff --git a/app/plug-in/gimpplugin-message.c b/app/plug-in/gimpplugin-message.c index 080afe3a66..16ed41dc2c 100644 --- a/app/plug-in/gimpplugin-message.c +++ b/app/plug-in/gimpplugin-message.c @@ -550,6 +550,7 @@ plug_in_handle_temp_proc_return (PlugIn *plug_in, plug_in_handle_proc_return_priv (plug_in, proc_return, TRUE); plug_in_main_loop_quit (plug_in); + plug_in_proc_frame_pop (plug_in); } else { diff --git a/app/plug-in/gimpplugin.c b/app/plug-in/gimpplugin.c index 109e083fd7..5a274b6b4e 100644 --- a/app/plug-in/gimpplugin.c +++ b/app/plug-in/gimpplugin.c @@ -878,7 +878,7 @@ plug_in_get_proc_frame (PlugIn *plug_in) return &plug_in->main_proc_frame; } -void +PlugInProcFrame * plug_in_proc_frame_push (PlugIn *plug_in, GimpContext *context, GimpProgress *progress, @@ -886,15 +886,17 @@ plug_in_proc_frame_push (PlugIn *plug_in, { PlugInProcFrame *proc_frame; - g_return_if_fail (plug_in != NULL); - g_return_if_fail (GIMP_IS_CONTEXT (context)); - g_return_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress)); - g_return_if_fail (proc_rec != NULL); + g_return_val_if_fail (plug_in != NULL, NULL); + g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL); + g_return_val_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress), NULL); + g_return_val_if_fail (proc_rec != NULL, NULL); proc_frame = plug_in_proc_frame_new (context, progress, proc_rec); plug_in->temp_proc_frames = g_list_prepend (plug_in->temp_proc_frames, proc_frame); + + return proc_frame; } void @@ -907,7 +909,7 @@ plug_in_proc_frame_pop (PlugIn *plug_in) proc_frame = (PlugInProcFrame *) plug_in->temp_proc_frames->data; - plug_in_proc_frame_free (proc_frame, plug_in); + plug_in_proc_frame_unref (proc_frame, plug_in); plug_in->temp_proc_frames = g_list_remove (plug_in->temp_proc_frames, proc_frame); diff --git a/app/plug-in/gimpplugin.h b/app/plug-in/gimpplugin.h index 2d642b22ac..e4fee6fa34 100644 --- a/app/plug-in/gimpplugin.h +++ b/app/plug-in/gimpplugin.h @@ -97,7 +97,7 @@ void plug_in_pop (Gimp *gimp); PlugInProcFrame * plug_in_get_proc_frame (PlugIn *plug_in); -void plug_in_proc_frame_push (PlugIn *plug_in, +PlugInProcFrame * plug_in_proc_frame_push (PlugIn *plug_in, GimpContext *context, GimpProgress *progress, ProcRecord *proc_rec); diff --git a/app/plug-in/gimppluginmanager-call.c b/app/plug-in/gimppluginmanager-call.c index 0ec226f77d..976cc5943d 100644 --- a/app/plug-in/gimppluginmanager-call.c +++ b/app/plug-in/gimppluginmanager-call.c @@ -250,9 +250,11 @@ plug_in_temp_run (ProcRecord *proc_rec, if (plug_in) { - GPProcRun proc_run; + PlugInProcFrame *proc_frame; + GPProcRun proc_run; - plug_in_proc_frame_push (plug_in, context, progress, proc_rec); + proc_frame = plug_in_proc_frame_push (plug_in, context, progress, + proc_rec); proc_run.name = proc_rec->name; proc_run.nparams = argc; @@ -271,14 +273,17 @@ plug_in_temp_run (ProcRecord *proc_rec, plug_in_params_destroy (proc_run.params, proc_run.nparams, FALSE); plug_in_ref (plug_in); + plug_in_proc_frame_ref (proc_frame); plug_in_main_loop (plug_in); - return_vals = plug_in_get_return_vals (plug_in, - plug_in->temp_proc_frames->data); + return_vals = plug_in_get_return_vals (plug_in, proc_frame); - plug_in_proc_frame_pop (plug_in); + /* main_loop is quit and proc_frame is popped in + * plug_in_handle_temp_proc_return() + */ + plug_in_proc_frame_unref (proc_frame, plug_in); plug_in_unref (plug_in); } diff --git a/app/plug-in/gimppluginmanager-run.c b/app/plug-in/gimppluginmanager-run.c index 0ec226f77d..976cc5943d 100644 --- a/app/plug-in/gimppluginmanager-run.c +++ b/app/plug-in/gimppluginmanager-run.c @@ -250,9 +250,11 @@ plug_in_temp_run (ProcRecord *proc_rec, if (plug_in) { - GPProcRun proc_run; + PlugInProcFrame *proc_frame; + GPProcRun proc_run; - plug_in_proc_frame_push (plug_in, context, progress, proc_rec); + proc_frame = plug_in_proc_frame_push (plug_in, context, progress, + proc_rec); proc_run.name = proc_rec->name; proc_run.nparams = argc; @@ -271,14 +273,17 @@ plug_in_temp_run (ProcRecord *proc_rec, plug_in_params_destroy (proc_run.params, proc_run.nparams, FALSE); plug_in_ref (plug_in); + plug_in_proc_frame_ref (proc_frame); plug_in_main_loop (plug_in); - return_vals = plug_in_get_return_vals (plug_in, - plug_in->temp_proc_frames->data); + return_vals = plug_in_get_return_vals (plug_in, proc_frame); - plug_in_proc_frame_pop (plug_in); + /* main_loop is quit and proc_frame is popped in + * plug_in_handle_temp_proc_return() + */ + plug_in_proc_frame_unref (proc_frame, plug_in); plug_in_unref (plug_in); } diff --git a/app/plug-in/gimppluginprocframe.c b/app/plug-in/gimppluginprocframe.c index 396f0d9231..47896ed41d 100644 --- a/app/plug-in/gimppluginprocframe.c +++ b/app/plug-in/gimppluginprocframe.c @@ -46,6 +46,8 @@ plug_in_proc_frame_new (GimpContext *context, proc_frame = g_new0 (PlugInProcFrame, 1); + proc_frame->ref_count = 1; + plug_in_proc_frame_init (proc_frame, context, progress, proc_rec); return proc_frame; @@ -115,3 +117,26 @@ plug_in_proc_frame_free (PlugInProcFrame *proc_frame, g_free (proc_frame); } + +PlugInProcFrame * +plug_in_proc_frame_ref (PlugInProcFrame *proc_frame) +{ + g_return_val_if_fail (proc_frame != NULL, NULL); + + proc_frame->ref_count++; + + return proc_frame; +} + +void +plug_in_proc_frame_unref (PlugInProcFrame *proc_frame, + PlugIn *plug_in) +{ + g_return_if_fail (proc_frame != NULL); + g_return_if_fail (plug_in != NULL); + + proc_frame->ref_count--; + + if (proc_frame->ref_count < 1) + plug_in_proc_frame_free (proc_frame, plug_in); +} diff --git a/app/plug-in/gimppluginprocframe.h b/app/plug-in/gimppluginprocframe.h index cae0ca5d51..348155e18e 100644 --- a/app/plug-in/gimppluginprocframe.h +++ b/app/plug-in/gimppluginprocframe.h @@ -24,6 +24,8 @@ struct _PlugInProcFrame { + gint ref_count; + GimpContext *main_context; GList *context_stack; @@ -52,5 +54,9 @@ void plug_in_proc_frame_dispose (PlugInProcFrame *proc_frame, void plug_in_proc_frame_free (PlugInProcFrame *proc_frame, PlugIn *plug_in); +PlugInProcFrame * plug_in_proc_frame_ref (PlugInProcFrame *proc_frame); +void plug_in_proc_frame_unref (PlugInProcFrame *proc_frame, + PlugIn *plug_in); + #endif /* __PLUG_IN_PROC_FRAME_H__ */ diff --git a/app/plug-in/plug-in-message.c b/app/plug-in/plug-in-message.c index 080afe3a66..16ed41dc2c 100644 --- a/app/plug-in/plug-in-message.c +++ b/app/plug-in/plug-in-message.c @@ -550,6 +550,7 @@ plug_in_handle_temp_proc_return (PlugIn *plug_in, plug_in_handle_proc_return_priv (plug_in, proc_return, TRUE); plug_in_main_loop_quit (plug_in); + plug_in_proc_frame_pop (plug_in); } else { diff --git a/app/plug-in/plug-in-proc-frame.c b/app/plug-in/plug-in-proc-frame.c index 396f0d9231..47896ed41d 100644 --- a/app/plug-in/plug-in-proc-frame.c +++ b/app/plug-in/plug-in-proc-frame.c @@ -46,6 +46,8 @@ plug_in_proc_frame_new (GimpContext *context, proc_frame = g_new0 (PlugInProcFrame, 1); + proc_frame->ref_count = 1; + plug_in_proc_frame_init (proc_frame, context, progress, proc_rec); return proc_frame; @@ -115,3 +117,26 @@ plug_in_proc_frame_free (PlugInProcFrame *proc_frame, g_free (proc_frame); } + +PlugInProcFrame * +plug_in_proc_frame_ref (PlugInProcFrame *proc_frame) +{ + g_return_val_if_fail (proc_frame != NULL, NULL); + + proc_frame->ref_count++; + + return proc_frame; +} + +void +plug_in_proc_frame_unref (PlugInProcFrame *proc_frame, + PlugIn *plug_in) +{ + g_return_if_fail (proc_frame != NULL); + g_return_if_fail (plug_in != NULL); + + proc_frame->ref_count--; + + if (proc_frame->ref_count < 1) + plug_in_proc_frame_free (proc_frame, plug_in); +} diff --git a/app/plug-in/plug-in-proc-frame.h b/app/plug-in/plug-in-proc-frame.h index cae0ca5d51..348155e18e 100644 --- a/app/plug-in/plug-in-proc-frame.h +++ b/app/plug-in/plug-in-proc-frame.h @@ -24,6 +24,8 @@ struct _PlugInProcFrame { + gint ref_count; + GimpContext *main_context; GList *context_stack; @@ -52,5 +54,9 @@ void plug_in_proc_frame_dispose (PlugInProcFrame *proc_frame, void plug_in_proc_frame_free (PlugInProcFrame *proc_frame, PlugIn *plug_in); +PlugInProcFrame * plug_in_proc_frame_ref (PlugInProcFrame *proc_frame); +void plug_in_proc_frame_unref (PlugInProcFrame *proc_frame, + PlugIn *plug_in); + #endif /* __PLUG_IN_PROC_FRAME_H__ */ diff --git a/app/plug-in/plug-in-run.c b/app/plug-in/plug-in-run.c index 0ec226f77d..976cc5943d 100644 --- a/app/plug-in/plug-in-run.c +++ b/app/plug-in/plug-in-run.c @@ -250,9 +250,11 @@ plug_in_temp_run (ProcRecord *proc_rec, if (plug_in) { - GPProcRun proc_run; + PlugInProcFrame *proc_frame; + GPProcRun proc_run; - plug_in_proc_frame_push (plug_in, context, progress, proc_rec); + proc_frame = plug_in_proc_frame_push (plug_in, context, progress, + proc_rec); proc_run.name = proc_rec->name; proc_run.nparams = argc; @@ -271,14 +273,17 @@ plug_in_temp_run (ProcRecord *proc_rec, plug_in_params_destroy (proc_run.params, proc_run.nparams, FALSE); plug_in_ref (plug_in); + plug_in_proc_frame_ref (proc_frame); plug_in_main_loop (plug_in); - return_vals = plug_in_get_return_vals (plug_in, - plug_in->temp_proc_frames->data); + return_vals = plug_in_get_return_vals (plug_in, proc_frame); - plug_in_proc_frame_pop (plug_in); + /* main_loop is quit and proc_frame is popped in + * plug_in_handle_temp_proc_return() + */ + plug_in_proc_frame_unref (proc_frame, plug_in); plug_in_unref (plug_in); } diff --git a/app/plug-in/plug-in.c b/app/plug-in/plug-in.c index 109e083fd7..5a274b6b4e 100644 --- a/app/plug-in/plug-in.c +++ b/app/plug-in/plug-in.c @@ -878,7 +878,7 @@ plug_in_get_proc_frame (PlugIn *plug_in) return &plug_in->main_proc_frame; } -void +PlugInProcFrame * plug_in_proc_frame_push (PlugIn *plug_in, GimpContext *context, GimpProgress *progress, @@ -886,15 +886,17 @@ plug_in_proc_frame_push (PlugIn *plug_in, { PlugInProcFrame *proc_frame; - g_return_if_fail (plug_in != NULL); - g_return_if_fail (GIMP_IS_CONTEXT (context)); - g_return_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress)); - g_return_if_fail (proc_rec != NULL); + g_return_val_if_fail (plug_in != NULL, NULL); + g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL); + g_return_val_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress), NULL); + g_return_val_if_fail (proc_rec != NULL, NULL); proc_frame = plug_in_proc_frame_new (context, progress, proc_rec); plug_in->temp_proc_frames = g_list_prepend (plug_in->temp_proc_frames, proc_frame); + + return proc_frame; } void @@ -907,7 +909,7 @@ plug_in_proc_frame_pop (PlugIn *plug_in) proc_frame = (PlugInProcFrame *) plug_in->temp_proc_frames->data; - plug_in_proc_frame_free (proc_frame, plug_in); + plug_in_proc_frame_unref (proc_frame, plug_in); plug_in->temp_proc_frames = g_list_remove (plug_in->temp_proc_frames, proc_frame); diff --git a/app/plug-in/plug-in.h b/app/plug-in/plug-in.h index 2d642b22ac..e4fee6fa34 100644 --- a/app/plug-in/plug-in.h +++ b/app/plug-in/plug-in.h @@ -97,7 +97,7 @@ void plug_in_pop (Gimp *gimp); PlugInProcFrame * plug_in_get_proc_frame (PlugIn *plug_in); -void plug_in_proc_frame_push (PlugIn *plug_in, +PlugInProcFrame * plug_in_proc_frame_push (PlugIn *plug_in, GimpContext *context, GimpProgress *progress, ProcRecord *proc_rec);