]> granicus.if.org Git - imagemagick/blobdiff - MagickCore/module.c
(no commit message)
[imagemagick] / MagickCore / module.c
index bf3ce2eee0115e489b25c57701d2d8466fadb64c..94acdd43aae34674712bedf4100569de8803d350 100644 (file)
@@ -17,7 +17,7 @@
 %                                March 2000                                   %
 %                                                                             %
 %                                                                             %
-%  Copyright 1999-2013 ImageMagick Studio LLC, a non-profit organization      %
+%  Copyright 1999-2014 ImageMagick Studio LLC, a non-profit organization      %
 %  dedicated to making software imaging solutions freely available.           %
 %                                                                             %
 %  You may not use this file except in compliance with the License.  You may  %
@@ -93,9 +93,6 @@ static SemaphoreInfo
 
 static SplayTreeInfo
   *module_list = (SplayTreeInfo *) NULL;
-
-static volatile MagickBooleanType
-  instantiate_module = MagickFalse;
 \f
 /*
   Forward declarations.
@@ -105,7 +102,7 @@ static const ModuleInfo
 
 static MagickBooleanType
   GetMagickModulePath(const char *,MagickModuleType,char *,ExceptionInfo *),
-  InitializeModuleList(ExceptionInfo *),
+  IsModuleTreeInstantiated(ExceptionInfo *),
   UnregisterModule(const ModuleInfo *,ExceptionInfo *);
 
 static void
@@ -184,13 +181,6 @@ MagickExport void DestroyModuleList(void)
 #if defined(MAGICKCORE_MODULES_SUPPORT)
   if (module_list != (SplayTreeInfo *) NULL)
     module_list=DestroySplayTree(module_list);
-  if (instantiate_module != MagickFalse)
-    {
-#if !defined(MAGICKCORE_JP2_DELEGATE)
-      (void) lt_dlexit();  /* Jasper has an errant atexit() handler */
-#endif
-      instantiate_module=MagickFalse;
-    }
 #endif
   UnlockSemaphoreInfo(module_semaphore);
 }
@@ -225,29 +215,26 @@ MagickExport void DestroyModuleList(void)
 */
 MagickExport ModuleInfo *GetModuleInfo(const char *tag,ExceptionInfo *exception)
 {
-  if ((module_list == (SplayTreeInfo *) NULL) ||
-      (instantiate_module == MagickFalse))
-    if (InitializeModuleList(exception) == MagickFalse)
-      return((ModuleInfo *) NULL);
-  if ((module_list == (SplayTreeInfo *) NULL) ||
-      (GetNumberOfNodesInSplayTree(module_list) == 0))
+  ModuleInfo
+    *module_info;
+
+  if (IsModuleTreeInstantiated(exception) == MagickFalse)
     return((ModuleInfo *) NULL);
+  LockSemaphoreInfo(module_semaphore);
+  ResetSplayTreeIterator(module_list);
   if ((tag == (const char *) NULL) || (LocaleCompare(tag,"*") == 0))
     {
-      ModuleInfo
-        *p;
-
 #if defined(MAGICKCORE_MODULES_SUPPORT)
       if (LocaleCompare(tag,"*") == 0)
         (void) OpenModules(exception);
 #endif
-      LockSemaphoreInfo(module_semaphore);
-      ResetSplayTreeIterator(module_list);
-      p=(ModuleInfo *) GetNextValueInSplayTree(module_list);
+      module_info=(ModuleInfo *) GetNextValueInSplayTree(module_list);
       UnlockSemaphoreInfo(module_semaphore);
-      return(p);
+      return(module_info);
     }
-  return((ModuleInfo *) GetValueFromSplayTree(module_list,tag));
+  module_info=(ModuleInfo *) GetValueFromSplayTree(module_list,tag);
+  UnlockSemaphoreInfo(module_semaphore);
+  return(module_info);
 }
 \f
 /*
@@ -470,8 +457,7 @@ MagickExport char **GetModuleList(const char *pattern,
       modules=(char **) RelinquishMagickMemory(modules);
       return((char **) NULL);
     }
-  buffer=(struct dirent *) AcquireMagickMemory(sizeof(*buffer)+
-    FILENAME_MAX+1);
+  buffer=(struct dirent *) AcquireMagickMemory(sizeof(*buffer)+FILENAME_MAX+1);
   if (buffer == (struct dirent *) NULL)
     ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
   i=0;
@@ -510,7 +496,7 @@ MagickExport char **GetModuleList(const char *pattern,
   if (modules == (char **) NULL)
     {
       (void) ThrowMagickException(exception,GetMagickModule(),ConfigureError,
-        "MemoryAllocationFailed","'%s'",pattern);
+        "MemoryAllocationFailed","`%s'",pattern);
       return((char **) NULL);
     }
   qsort((void *) modules,(size_t) i,sizeof(*modules),ModuleCompare);
@@ -676,7 +662,7 @@ static MagickBooleanType GetMagickModulePath(const char *filename,
       if (key_value == (unsigned char *) NULL)
         {
           ThrowMagickException(exception,GetMagickModule(),ConfigureError,
-            "RegistryKeyLookupFailed","'%s'",registery_key);
+            "RegistryKeyLookupFailed","`%s'",registery_key);
           return(MagickFalse);
         }
       (void) FormatLocaleString(path,MaxTextExtent,"%s%s%s",(char *) key_value,
@@ -798,9 +784,10 @@ static MagickBooleanType GetMagickModulePath(const char *filename,
     if (home != (char *) NULL)
       {
         /*
-          Search $HOME/.magick.
+          Search $HOME/.config/ImageMagick.
         */
-        (void) FormatLocaleString(path,MaxTextExtent,"%s%s.magick%s%s",home,
+        (void) FormatLocaleString(path,MaxTextExtent,
+          "%s%s.config%sImageMagick%s%s",home,DirectorySeparator,
           DirectorySeparator,DirectorySeparator,filename);
         home=DestroyString(home);
         if (IsPathAccessible(path) != MagickFalse)
@@ -815,7 +802,6 @@ static MagickBooleanType GetMagickModulePath(const char *filename,
   if (exception->severity < ConfigureError)
     ThrowFileException(exception,ConfigureWarning,"UnableToOpenModuleFile",
       path);
-  return(MagickFalse);
 #endif
   return(MagickFalse);
 }
@@ -825,17 +811,18 @@ static MagickBooleanType GetMagickModulePath(const char *filename,
 %                                                                             %
 %                                                                             %
 %                                                                             %
-%   I n i t i a l i z e M o d u l e L i s t                                   %
+%   I s M o d u l e T r e e I n s t a n t i a t e d                           %
 %                                                                             %
 %                                                                             %
 %                                                                             %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
-%  InitializeModuleList() initializes the module loader.
+%  IsModuleTreeInstantiated() determines if the module tree is instantiated.
+%  If not, it instantiates the tree and returns it.
 %
-%  The format of the InitializeModuleList() method is:
+%  The format of the IsModuleTreeInstantiated() method is:
 %
-%      InitializeModuleList(Exceptioninfo *exception)
+%      IsModuleTreeInstantiated(Exceptioninfo *exception)
 %
 %  A description of each parameter follows.
 %
@@ -863,17 +850,15 @@ static void *DestroyModuleNode(void *module_info)
   return(RelinquishMagickMemory(p));
 }
 
-static MagickBooleanType InitializeModuleList(
+static MagickBooleanType IsModuleTreeInstantiated(
   ExceptionInfo *magick_unused(exception))
 {
-  if ((module_list == (SplayTreeInfo *) NULL) &&
-      (instantiate_module == MagickFalse))
+  if (module_list == (SplayTreeInfo *) NULL)
     {
       if (module_semaphore == (SemaphoreInfo *) NULL)
-        AcquireSemaphoreInfo(&module_semaphore);
+        ActivateSemaphoreInfo(&module_semaphore);
       LockSemaphoreInfo(module_semaphore);
-      if ((module_list == (SplayTreeInfo *) NULL) &&
-          (instantiate_module == MagickFalse))
+      if (module_list == (SplayTreeInfo *) NULL)
         {
           MagickBooleanType
             status;
@@ -895,7 +880,6 @@ static MagickBooleanType InitializeModuleList(
           if (lt_dlinit() != 0)
             ThrowFatalException(ModuleFatalError,
               "UnableToInitializeModuleLoader");
-          instantiate_module=MagickTrue;
         }
       UnlockSemaphoreInfo(module_semaphore);
     }
@@ -977,7 +961,7 @@ MagickExport MagickBooleanType InvokeDynamicImageFilter(const char *tag,
     {
       errno=EPERM;
       (void) ThrowMagickException(exception,GetMagickModule(),PolicyError,
-        "NotAuthorized","'%s'",tag);
+        "NotAuthorized","`%s'",tag);
       return(MagickFalse);
     }
   TagToFilterModuleName(tag,name);
@@ -1165,9 +1149,10 @@ MagickPrivate MagickBooleanType ModuleComponentGenesis(void)
   MagickBooleanType
     status;
 
-  AcquireSemaphoreInfo(&module_semaphore);
+  if (module_semaphore == (SemaphoreInfo *) NULL)
+    module_semaphore=AcquireSemaphoreInfo();
   exception=AcquireExceptionInfo();
-  status=InitializeModuleList(exception);
+  status=IsModuleTreeInstantiated(exception);
   exception=DestroyExceptionInfo(exception);
   return(status);
 }
@@ -1193,9 +1178,9 @@ MagickPrivate MagickBooleanType ModuleComponentGenesis(void)
 MagickPrivate void ModuleComponentTerminus(void)
 {
   if (module_semaphore == (SemaphoreInfo *) NULL)
-    AcquireSemaphoreInfo(&module_semaphore);
+    ActivateSemaphoreInfo(&module_semaphore);
   DestroyModuleList();
-  DestroySemaphoreInfo(&module_semaphore);
+  RelinquishSemaphoreInfo(&module_semaphore);
 }
 \f
 /*
@@ -1423,7 +1408,7 @@ static const ModuleInfo *RegisterModule(const ModuleInfo *module_info,
   status=AddValueToSplayTree(module_list,module_info->tag,module_info);
   if (status == MagickFalse)
     (void) ThrowMagickException(exception,GetMagickModule(),ResourceLimitError,
-      "MemoryAllocationFailed","'%s'",module_info->tag);
+      "MemoryAllocationFailed","`%s'",module_info->tag);
   return(module_info);
 }
 \f
@@ -1613,6 +1598,12 @@ static MagickBooleanType UnregisterModule(const ModuleInfo *module_info,
   return(MagickTrue);
 }
 #else
+
+#if !defined(MAGICKCORE_BUILD_MODULES)
+extern size_t
+  analyzeImage(Image **,const int,const char **,ExceptionInfo *);
+#endif
+
 MagickExport MagickBooleanType ListModuleInfo(FILE *magick_unused(file),
   ExceptionInfo *magick_unused(exception))
 {
@@ -1634,7 +1625,7 @@ MagickExport MagickBooleanType InvokeDynamicImageFilter(const char *tag,
     {
       errno=EPERM;
       (void) ThrowMagickException(exception,GetMagickModule(),PolicyError,
-        "NotAuthorized","'%s'",tag);
+        "NotAuthorized","`%s'",tag);
       return(MagickFalse);
     }
 #if defined(MAGICKCORE_BUILD_MODULES)
@@ -1644,9 +1635,6 @@ MagickExport MagickBooleanType InvokeDynamicImageFilter(const char *tag,
   (void) exception;
 #else
   {
-    extern size_t
-      analyzeImage(Image **,const int,const char **,ExceptionInfo *);
-
     ImageFilterHandler
       *image_filter;
 
@@ -1655,7 +1643,7 @@ MagickExport MagickBooleanType InvokeDynamicImageFilter(const char *tag,
       image_filter=(ImageFilterHandler *) analyzeImage;
     if (image_filter == (ImageFilterHandler *) NULL)
       (void) ThrowMagickException(exception,GetMagickModule(),ModuleError,
-        "UnableToLoadModule","'%s'",tag);
+        "UnableToLoadModule","`%s'",tag);
     else
       {
         size_t