From d033ddda1ba01ac0f472fda49bd421ed58b731e3 Mon Sep 17 00:00:00 2001 From: Michael Natterer Date: Thu, 4 May 2006 21:49:04 +0000 Subject: [PATCH] cleaned up a bit. 2006-05-04 Michael Natterer * app/plug-in/gimppluginshm.c: cleaned up a bit. (gimp_plug_in_shm_new): return NULL if anything goes wrong, instead of a GimpPlugInShm structure that contains no shm (we don't need multiple cases of "there is no shm"), * app/plug-in/gimppluginmanager.[ch] (gimp_plug_in_manager_get_shm_ID) (gimp_plug_in_manager_get_shm_addr): removed these functions. * app/plug-in/gimppluginmanager-call.c (gimp_plug_in_manager_call_run) * app/plug-in/gimpplugin-message.c (gimp_plug_in_handle_tile_req): get the shm ID and addr directly from manager->shm if it exists, use -1 and NULL otherwise. Unrelated: * app/plug-in/gimppluginmanager.c: move most stuff from gimp_plug_in_manager_exit() to gimp_plug_in_manager_finalize(). Simplify plug-in killing in _exit(). --- ChangeLog | 23 +++ app/plug-in/gimpplugin-message.c | 29 ++-- app/plug-in/gimppluginmanager-call.c | 4 +- app/plug-in/gimppluginmanager.c | 84 ++++------ app/plug-in/gimppluginmanager.h | 7 +- app/plug-in/gimppluginshm.c | 241 ++++++++++++++------------- 6 files changed, 202 insertions(+), 186 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7cad8c2c34..f44eee72ca 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,26 @@ +2006-05-04 Michael Natterer + + * app/plug-in/gimppluginshm.c: cleaned up a bit. + + (gimp_plug_in_shm_new): return NULL if anything goes wrong, + instead of a GimpPlugInShm structure that contains no shm (we + don't need multiple cases of "there is no shm"), + + * app/plug-in/gimppluginmanager.[ch] + (gimp_plug_in_manager_get_shm_ID) + (gimp_plug_in_manager_get_shm_addr): removed these functions. + + * app/plug-in/gimppluginmanager-call.c (gimp_plug_in_manager_call_run) + * app/plug-in/gimpplugin-message.c (gimp_plug_in_handle_tile_req): + get the shm ID and addr directly from manager->shm if it exists, + use -1 and NULL otherwise. + + Unrelated: + + * app/plug-in/gimppluginmanager.c: move most stuff from + gimp_plug_in_manager_exit() to gimp_plug_in_manager_finalize(). + Simplify plug-in killing in _exit(). + 2006-05-04 Sven Neumann * app/core/gimp-user-install.[ch]: added a "verbose" parameter. diff --git a/app/plug-in/gimpplugin-message.c b/app/plug-in/gimpplugin-message.c index eb876c6acb..1de00fe344 100644 --- a/app/plug-in/gimpplugin-message.c +++ b/app/plug-in/gimpplugin-message.c @@ -43,6 +43,7 @@ #include "gimpplugin.h" #include "gimpplugin-message.h" #include "gimppluginmanager.h" +#include "gimppluginshm.h" #include "plug-in-def.h" #include "plug-in-params.h" @@ -167,9 +168,6 @@ gimp_plug_in_handle_tile_req (GimpPlugIn *plug_in, GimpDrawable *drawable; TileManager *tm; Tile *tile; - gint shm_ID; - - shm_ID = gimp_plug_in_manager_get_shm_ID (plug_in->manager); if (tile_req->drawable_ID == -1) { @@ -181,7 +179,7 @@ gimp_plug_in_handle_tile_req (GimpPlugIn *plug_in, tile_data.bpp = 0; tile_data.width = 0; tile_data.height = 0; - tile_data.use_shm = (shm_ID == -1) ? FALSE : TRUE; + tile_data.use_shm = (plug_in->manager->shm != NULL); tile_data.data = NULL; if (! gp_tile_data_write (plug_in->my_write, &tile_data, plug_in)) @@ -239,7 +237,7 @@ gimp_plug_in_handle_tile_req (GimpPlugIn *plug_in, if (tile_data.use_shm) memcpy (tile_data_pointer (tile, 0, 0), - gimp_plug_in_manager_get_shm_addr (plug_in->manager), + gimp_plug_in_shm_get_addr (plug_in->manager->shm), tile_size (tile)); else memcpy (tile_data_pointer (tile, 0, 0), @@ -296,10 +294,10 @@ gimp_plug_in_handle_tile_req (GimpPlugIn *plug_in, tile_data.bpp = tile_bpp (tile); tile_data.width = tile_ewidth (tile); tile_data.height = tile_eheight (tile); - tile_data.use_shm = (shm_ID == -1) ? FALSE : TRUE; + tile_data.use_shm = (plug_in->manager->shm != NULL); if (tile_data.use_shm) - memcpy (gimp_plug_in_manager_get_shm_addr (plug_in->manager), + memcpy (gimp_plug_in_shm_get_addr (plug_in->manager->shm), tile_data_pointer (tile, 0, 0), tile_size (tile)); else @@ -450,15 +448,16 @@ gimp_plug_in_handle_proc_return (GimpPlugIn *plug_in, GimpPlugInProcFrame *proc_frame = &plug_in->main_proc_frame; if (proc_frame->main_loop) - proc_frame->return_vals = - plug_in_params_to_args (proc_frame->procedure->values, - proc_frame->procedure->num_values, - proc_return->params, - proc_return->nparams, - TRUE, TRUE); + { + proc_frame->return_vals = + plug_in_params_to_args (proc_frame->procedure->values, + proc_frame->procedure->num_values, + proc_return->params, + proc_return->nparams, + TRUE, TRUE); - if (proc_frame->main_loop) - g_main_loop_quit (proc_frame->main_loop); + g_main_loop_quit (proc_frame->main_loop); + } gimp_plug_in_close (plug_in, FALSE); } diff --git a/app/plug-in/gimppluginmanager-call.c b/app/plug-in/gimppluginmanager-call.c index dff34ed9a8..f4d5cc9e46 100644 --- a/app/plug-in/gimppluginmanager-call.c +++ b/app/plug-in/gimppluginmanager-call.c @@ -43,6 +43,7 @@ #include "gimppluginmanager.h" #define __YES_I_NEED_GIMP_PLUG_IN_MANAGER_CALL__ #include "gimppluginmanager-call.h" +#include "gimppluginshm.h" #include "plug-in-def.h" #include "plug-in-params.h" @@ -171,7 +172,8 @@ gimp_plug_in_manager_call_run (GimpPlugInManager *manager, config.version = GIMP_PROTOCOL_VERSION; config.tile_width = TILE_WIDTH; config.tile_height = TILE_HEIGHT; - config.shm_ID = gimp_plug_in_manager_get_shm_ID (manager); + config.shm_ID = (manager->shm ? + gimp_plug_in_shm_get_ID (manager->shm) : -1); config.check_size = display_config->transparency_size; config.check_type = display_config->transparency_type; config.show_help_button = (gui_config->use_help && diff --git a/app/plug-in/gimppluginmanager.c b/app/plug-in/gimppluginmanager.c index df4e1e052b..7dfa92dd31 100644 --- a/app/plug-in/gimppluginmanager.c +++ b/app/plug-in/gimppluginmanager.c @@ -126,14 +126,25 @@ gimp_plug_in_manager_class_init (GimpPlugInManagerClass *klass) static void gimp_plug_in_manager_init (GimpPlugInManager *manager) { + manager->gimp = NULL; + + manager->plug_in_defs = NULL; + manager->write_pluginrc = FALSE; + manager->plug_in_procedures = NULL; manager->load_procs = NULL; manager->save_procs = NULL; - manager->interpreter_db = gimp_interpreter_db_new (); - manager->environ_table = gimp_environ_table_new (); - manager->debug = NULL; - manager->data_list = NULL; + manager->current_plug_in = NULL; + manager->open_plug_ins = NULL; + manager->plug_in_stack = NULL; + manager->last_plug_ins = NULL; + + manager->shm = NULL; + manager->interpreter_db = gimp_interpreter_db_new (); + manager->environ_table = gimp_environ_table_new (); + manager->debug = NULL; + manager->data_list = NULL; } static void @@ -153,12 +164,26 @@ gimp_plug_in_manager_finalize (GObject *object) manager->save_procs = NULL; } + if (manager->plug_in_procedures) + { + g_slist_foreach (manager->plug_in_procedures, + (GFunc) g_object_unref, NULL); + g_slist_free (manager->plug_in_procedures); + manager->plug_in_procedures = NULL; + } + if (manager->last_plug_ins) { g_slist_free (manager->last_plug_ins); manager->last_plug_ins = NULL; } + if (manager->shm) + { + gimp_plug_in_shm_free (manager->shm); + manager->shm = NULL; + } + if (manager->environ_table) { g_object_unref (manager->environ_table); @@ -171,6 +196,12 @@ gimp_plug_in_manager_finalize (GObject *object) manager->interpreter_db = NULL; } + if (manager->debug) + { + gimp_plug_in_debug_free (manager->debug); + manager->debug = NULL; + } + gimp_plug_in_manager_menu_branch_exit (manager); gimp_plug_in_manager_locale_domain_exit (manager); gimp_plug_in_manager_help_domain_exit (manager); @@ -548,35 +579,10 @@ gimp_plug_in_manager_restore (GimpPlugInManager *manager, void gimp_plug_in_manager_exit (GimpPlugInManager *manager) { - GSList *list; - g_return_if_fail (GIMP_IS_PLUG_IN_MANAGER (manager)); - if (manager->debug) - { - gimp_plug_in_debug_free (manager->debug); - manager->debug = NULL; - } - - if (manager->shm) - { - gimp_plug_in_shm_free (manager->shm); - manager->shm = NULL; - } - - list = manager->open_plug_ins; - while (list) - { - GimpPlugIn *plug_in = list->data; - - list = list->next; - - gimp_plug_in_close (plug_in, TRUE); - } - - g_slist_foreach (manager->plug_in_procedures, (GFunc) g_object_unref, NULL); - g_slist_free (manager->plug_in_procedures); - manager->plug_in_procedures = NULL; + while (manager->open_plug_ins) + gimp_plug_in_close (manager->open_plug_ins->data, TRUE); } void @@ -683,22 +689,6 @@ gimp_plug_in_manager_set_last_plug_in (GimpPlugInManager *manager, g_signal_emit (manager, manager_signals[LAST_PLUG_INS_CHANGED], 0); } -gint -gimp_plug_in_manager_get_shm_ID (GimpPlugInManager *manager) -{ - g_return_val_if_fail (GIMP_IS_PLUG_IN_MANAGER (manager), -1); - - return manager->shm ? gimp_plug_in_shm_get_ID (manager->shm) : -1; -} - -guchar * -gimp_plug_in_manager_get_shm_addr (GimpPlugInManager *manager) -{ - g_return_val_if_fail (GIMP_IS_PLUG_IN_MANAGER (manager), NULL); - - return manager->shm ? gimp_plug_in_shm_get_addr (manager->shm) : NULL; -} - void gimp_plug_in_manager_plug_in_push (GimpPlugInManager *manager, GimpPlugIn *plug_in) diff --git a/app/plug-in/gimppluginmanager.h b/app/plug-in/gimppluginmanager.h index daa193bef2..73a3175bbd 100644 --- a/app/plug-in/gimppluginmanager.h +++ b/app/plug-in/gimppluginmanager.h @@ -102,12 +102,9 @@ void gimp_plug_in_manager_remove_temp_proc (GimpPlugInManager *manager, void gimp_plug_in_manager_set_last_plug_in (GimpPlugInManager *manager, GimpPlugInProcedure *procedure); -gint gimp_plug_in_manager_get_shm_ID (GimpPlugInManager *manager); -guchar * gimp_plug_in_manager_get_shm_addr (GimpPlugInManager *manager); - -void gimp_plug_in_manager_plug_in_push (GimpPlugInManager *manager, +void gimp_plug_in_manager_plug_in_push (GimpPlugInManager *manager, GimpPlugIn *plug_in); -void gimp_plug_in_manager_plug_in_pop (GimpPlugInManager *manager); +void gimp_plug_in_manager_plug_in_pop (GimpPlugInManager *manager); #endif /* __GIMP_PLUG_IN_MANAGER_H__ */ diff --git a/app/plug-in/gimppluginshm.c b/app/plug-in/gimppluginshm.c index 2df898c002..a1d94af90e 100644 --- a/app/plug-in/gimppluginshm.c +++ b/app/plug-in/gimppluginshm.c @@ -69,6 +69,11 @@ #include "gimppluginshm.h" +#define TILE_MAP_SIZE (TILE_WIDTH * TILE_HEIGHT * 4) + +#define ERRMSG_SHM_DISABLE "Disabling shared memory tile transport" + + struct _GimpPlugInShm { gint shm_ID; @@ -80,10 +85,6 @@ struct _GimpPlugInShm }; -#define TILE_MAP_SIZE (TILE_WIDTH * TILE_HEIGHT * 4) - -#define ERRMSG_SHM_DISABLE "Disabling shared memory tile transport" - GimpPlugInShm * gimp_plug_in_shm_new (void) { @@ -94,136 +95,146 @@ gimp_plug_in_shm_new (void) GimpPlugInShm *shm = g_new0 (GimpPlugInShm, 1); -#if defined(USE_SYSV_SHM) - /* Use SysV shared memory mechanisms for transferring tile data. */ - shm->shm_ID = -1; - shm->shm_ID = shmget (IPC_PRIVATE, TILE_MAP_SIZE, IPC_CREAT | 0600); +#if defined(USE_SYSV_SHM) - if (shm->shm_ID != -1) - { - shm->shm_addr = (guchar *) shmat (shm->shm_ID, NULL, 0); + /* Use SysV shared memory mechanisms for transferring tile data. */ + { + shm->shm_ID = shmget (IPC_PRIVATE, TILE_MAP_SIZE, IPC_CREAT | 0600); - if (shm->shm_addr == (guchar *) -1) - { - g_warning ("shmat() failed: %s\n" ERRMSG_SHM_DISABLE, - g_strerror (errno)); - shmctl (shm->shm_ID, IPC_RMID, NULL); - shm->shm_ID = -1; - } + if (shm->shm_ID != -1) + { + shm->shm_addr = (guchar *) shmat (shm->shm_ID, NULL, 0); + + if (shm->shm_addr == (guchar *) -1) + { + g_printerr ("shmat() failed: %s\n" ERRMSG_SHM_DISABLE, + g_strerror (errno)); + shmctl (shm->shm_ID, IPC_RMID, NULL); + shm->shm_ID = -1; + } #ifdef IPC_RMID_DEFERRED_RELEASE - if (shm->shm_addr != (guchar *) -1) - shmctl (shm->shm_ID, IPC_RMID, NULL); + if (shm->shm_addr != (guchar *) -1) + shmctl (shm->shm_ID, IPC_RMID, NULL); #endif - } - else - { - g_warning ("shmget() failed: %s\n" ERRMSG_SHM_DISABLE, - g_strerror (errno)); - } + } + else + { + g_printerr ("shmget() failed: %s\n" ERRMSG_SHM_DISABLE, + g_strerror (errno)); + } + } #elif defined(USE_WIN32_SHM) /* Use Win32 shared memory mechanisms for transferring tile data. */ + { + gint pid; + gchar fileMapName[MAX_PATH]; - gint pid; - gchar fileMapName[MAX_PATH]; + /* Our shared memory id will be our process ID */ + pid = GetCurrentProcessId (); - shm->shm_ID = -1; + /* From the id, derive the file map name */ + g_snprintf (fileMapName, sizeof (fileMapName), "GIMP%d.SHM", pid); - /* Our shared memory id will be our process ID */ - pid = GetCurrentProcessId (); + /* Create the file mapping into paging space */ + shm->shm_handle = CreateFileMapping ((HANDLE) 0xFFFFFFFF, NULL, + PAGE_READWRITE, 0, + TILE_MAP_SIZE, + fileMapName); - /* From the id, derive the file map name */ - g_snprintf (fileMapName, sizeof (fileMapName), "GIMP%d.SHM", pid); + if (shm->shm_handle) + { + /* Map the shared memory into our address space for use */ + shm->shm_addr = (guchar *) MapViewOfFile (shm->shm_handle, + FILE_MAP_ALL_ACCESS, + 0, 0, TILE_MAP_SIZE); - /* Create the file mapping into paging space */ - shm->shm_handle = CreateFileMapping ((HANDLE) 0xFFFFFFFF, NULL, - PAGE_READWRITE, 0, - TILE_MAP_SIZE, - fileMapName); - - if (shm->shm_handle) - { - /* Map the shared memory into our address space for use */ - shm->shm_addr = (guchar *) MapViewOfFile (shm->shm_handle, - FILE_MAP_ALL_ACCESS, - 0, 0, TILE_MAP_SIZE); - - /* Verify that we mapped our view */ - if (shm->shm_addr) - shm->shm_ID = pid; - else - g_warning ("MapViewOfFile error: %d... " ERRMSG_SHM_DISABLE, - GetLastError ()); - } - else - { - g_warning ("CreateFileMapping error: %d... " ERRMSG_SHM_DISABLE, - GetLastError ()); - } + /* Verify that we mapped our view */ + if (shm->shm_addr) + { + shm->shm_ID = pid; + } + else + { + g_printerr ("MapViewOfFile error: %d... " ERRMSG_SHM_DISABLE, + GetLastError ()); + } + } + else + { + g_printerr ("CreateFileMapping error: %d... " ERRMSG_SHM_DISABLE, + GetLastError ()); + } + } #elif defined(USE_POSIX_SHM) /* Use POSIX shared memory mechanisms for transferring tile data. */ + { + gint pid; + gchar shm_handle[32]; + gint shm_fd; - gint pid; - gchar shm_handle[32]; - gint shm_fd; + /* Our shared memory id will be our process ID */ + pid = getpid (); - shm->shm_ID = -1; + /* From the id, derive the file map name */ + g_snprintf (shm_handle, sizeof (shm_handle), "/gimp-shm-%d", pid); - /* Our shared memory id will be our process ID */ - pid = getpid (); + /* Create the file mapping into paging space */ + shm_fd = shm_open (shm_handle, O_RDWR | O_CREAT, 0600); - /* From the id, derive the file map name */ - g_snprintf (shm_handle, sizeof (shm_handle), "/gimp-shm-%d", pid); + if (shm_fd != -1) + { + if (ftruncate (shm_fd, TILE_MAP_SIZE) != -1) + { + /* Map the shared memory into our address space for use */ + shm->shm_addr = (guchar *) mmap (NULL, TILE_MAP_SIZE, + PROT_READ | PROT_WRITE, MAP_SHARED, + shm_fd, 0); - /* Create the file mapping into paging space */ - shm_fd = shm_open (shm_handle, O_RDWR | O_CREAT, 0600); + /* Verify that we mapped our view */ + if (shm->shm_addr != MAP_FAILED) + { + shm->shm_ID = pid; + } + else + { + g_printerr ("mmap() failed: %s\n" ERRMSG_SHM_DISABLE, + g_strerror (errno)); - if (shm_fd != -1) - { - if (ftruncate (shm_fd, TILE_MAP_SIZE) != -1) - { - /* Map the shared memory into our address space for use */ - shm->shm_addr = (guchar *) mmap (NULL, TILE_MAP_SIZE, - PROT_READ | PROT_WRITE, MAP_SHARED, - shm_fd, 0); + shm_unlink (shm_handle); + } + } + else + { + g_printerr ("ftruncate() failed: %s\n" ERRMSG_SHM_DISABLE, + g_strerror (errno)); - /* Verify that we mapped our view */ - if (shm->shm_addr != MAP_FAILED) - { - shm->shm_ID = pid; - } - else - { - g_warning ("mmap() failed: %s\n" ERRMSG_SHM_DISABLE, - g_strerror (errno)); + shm_unlink (shm_handle); + } - shm_unlink (shm_handle); - } - } - else - { - g_warning ("ftruncate() failed: %s\n" ERRMSG_SHM_DISABLE, - g_strerror (errno)); - - shm_unlink (shm_handle); - } - - close (shm_fd); - } - else - { - g_warning ("shm_open() failed: %s\n" ERRMSG_SHM_DISABLE, - g_strerror (errno)); - } + close (shm_fd); + } + else + { + g_printerr ("shm_open() failed: %s\n" ERRMSG_SHM_DISABLE, + g_strerror (errno)); + } + } #endif + if (shm->shm_ID == -1) + { + g_free (shm); + shm = NULL; + } + return shm; } @@ -232,32 +243,25 @@ gimp_plug_in_shm_free (GimpPlugInShm *shm) { g_return_if_fail (shm != NULL); + if (shm->shm_ID != -1) + { + #if defined (USE_SYSV_SHM) #ifndef IPC_RMID_DEFERRED_RELEASE - if (shm->shm_ID != -1) - { shmdt (shm->shm_addr); shmctl (shm->shm_ID, IPC_RMID, NULL); - } -#else /* IPC_RMID_DEFERRED_RELEASE */ - if (shm->shm_ID != -1) - { +#else shmdt (shm->shm_addr); - } -#endif +#endif /* IPC_RMID_DEFERRED_RELEASE */ #elif defined(USE_WIN32_SHM) - if (shm->shm_handle) - { - CloseHandle (shm->shm_handle); - } + if (shm->shm_handle) + CloseHandle (shm->shm_handle); #elif defined(USE_POSIX_SHM) - if (shm->shm_ID != -1) - { gchar shm_handle[32]; munmap (shm->shm_addr, TILE_MAP_SIZE); @@ -266,10 +270,11 @@ gimp_plug_in_shm_free (GimpPlugInShm *shm) shm->shm_ID); shm_unlink (shm_handle); - } #endif + } + g_free (shm); }