]> granicus.if.org Git - imagemagick/blobdiff - magick/magick.c
(no commit message)
[imagemagick] / magick / magick.c
index c94ae65b8f0916cd5e6f287bfc941eb4889b1412..01c145dbb0a1a05e4596019a85758cb51a595867 100644 (file)
@@ -18,7 +18,7 @@
 %                             November 1998                                   %
 %                                                                             %
 %                                                                             %
-%  Copyright 1999-2010 ImageMagick Studio LLC, a non-profit organization      %
+%  Copyright 1999-2011 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  %
@@ -41,7 +41,9 @@
   Include declarations.
 */
 #include "magick/studio.h"
+#include "magick/annotate.h"
 #include "magick/blob.h"
+#include "magick/blob-private.h"
 #include "magick/cache.h"
 #include "magick/coder.h"
 #include "magick/client.h"
@@ -67,6 +69,7 @@
 #include "magick/resource_.h"
 #include "magick/policy.h"
 #include "magick/semaphore.h"
+#include "magick/semaphore-private.h"
 #include "magick/signature-private.h"
 #include "magick/splay-tree.h"
 #include "magick/string_.h"
@@ -112,7 +115,8 @@ static SplayTreeInfo
   *magick_list = (SplayTreeInfo *) NULL;
 
 static volatile MagickBooleanType
-  instantiate_magick = MagickFalse;  /* double-checked locking pattern */
+  instantiate_magick = MagickFalse,
+  instantiate_magickcore = MagickFalse;
 \f
 /*
   Forward declarations.
@@ -467,7 +471,7 @@ MagickExport const MagickInfo *GetMagickInfo(const char *name,
 %  The format of the GetMagickInfoList function is:
 %
 %      const MagickInfo **GetMagickInfoList(const char *pattern,
-%        unsigned long *number_formats,ExceptionInfo *exception)
+%        size_t *number_formats,ExceptionInfo *exception)
 %
 %  A description of each parameter follows:
 %
@@ -499,7 +503,7 @@ static int MagickInfoCompare(const void *x,const void *y)
 #endif
 
 MagickExport const MagickInfo **GetMagickInfoList(const char *pattern,
-  unsigned long *number_formats,ExceptionInfo *exception)
+  size_t *number_formats,ExceptionInfo *exception)
 {
   const MagickInfo
     **formats;
@@ -507,7 +511,7 @@ MagickExport const MagickInfo **GetMagickInfoList(const char *pattern,
   register const MagickInfo
     *p;
 
-  register long
+  register ssize_t
     i;
 
   /*
@@ -515,7 +519,7 @@ MagickExport const MagickInfo **GetMagickInfoList(const char *pattern,
   */
   assert(pattern != (char *) NULL);
   (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern);
-  assert(number_formats != (unsigned long *) NULL);
+  assert(number_formats != (size_t *) NULL);
   *number_formats=0;
   p=GetMagickInfo("*",exception);
   if (p == (const MagickInfo *) NULL)
@@ -540,7 +544,7 @@ MagickExport const MagickInfo **GetMagickInfoList(const char *pattern,
   UnlockSemaphoreInfo(magick_semaphore);
   qsort((void *) formats,(size_t) i,sizeof(*formats),MagickInfoCompare);
   formats[i]=(MagickInfo *) NULL;
-  *number_formats=(unsigned long) i;
+  *number_formats=(size_t) i;
   return(formats);
 }
 \f
@@ -559,7 +563,7 @@ MagickExport const MagickInfo **GetMagickInfoList(const char *pattern,
 %
 %  The format of the GetMagickList function is:
 %
-%      char **GetMagickList(const char *pattern,unsigned long *number_formats,
+%      char **GetMagickList(const char *pattern,size_t *number_formats,
 %        ExceptionInfo *exception)
 %
 %  A description of each parameter follows:
@@ -592,7 +596,7 @@ static int MagickCompare(const void *x,const void *y)
 #endif
 
 MagickExport char **GetMagickList(const char *pattern,
-  unsigned long *number_formats,ExceptionInfo *exception)
+  size_t *number_formats,ExceptionInfo *exception)
 {
   char
     **formats;
@@ -600,7 +604,7 @@ MagickExport char **GetMagickList(const char *pattern,
   register const MagickInfo
     *p;
 
-  register long
+  register ssize_t
     i;
 
   /*
@@ -608,7 +612,7 @@ MagickExport char **GetMagickList(const char *pattern,
   */
   assert(pattern != (char *) NULL);
   (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern);
-  assert(number_formats != (unsigned long *) NULL);
+  assert(number_formats != (size_t *) NULL);
   *number_formats=0;
   p=GetMagickInfo("*",exception);
   if (p == (const MagickInfo *) NULL)
@@ -630,7 +634,7 @@ MagickExport char **GetMagickList(const char *pattern,
   UnlockSemaphoreInfo(magick_semaphore);
   qsort((void *) formats,(size_t) i,sizeof(*formats),MagickCompare);
   formats[i]=(char *) NULL;
-  *number_formats=(unsigned long) i;
+  *number_formats=(size_t) i;
   return(formats);
 }
 \f
@@ -934,15 +938,15 @@ MagickExport MagickBooleanType ListMagickInfo(FILE *file,
   const MagickInfo
     **magick_info;
 
-  long
-    j;
-
-  register long
+  register ssize_t
     i;
 
-  unsigned long
+  size_t
     number_formats;
 
+  ssize_t
+    j;
+
   if (file == (FILE *) NULL)
     file=stdout;
   magick_info=GetMagickInfoList("*",&number_formats,exception);
@@ -950,18 +954,19 @@ MagickExport MagickBooleanType ListMagickInfo(FILE *file,
     return(MagickFalse);
   ClearMagickException(exception);
 #if !defined(MAGICKCORE_MODULES_SUPPORT)
-  (void) fprintf(file,"   Format  Mode  Description\n");
+  (void) FormatLocaleFile(file,"   Format  Mode  Description\n");
 #else
-  (void) fprintf(file,"   Format  Module    Mode  Description\n");
+  (void) FormatLocaleFile(file,"   Format  Module    Mode  Description\n");
 #endif
-  (void) fprintf(file,"--------------------------------------------------------"
+  (void) FormatLocaleFile(file,
+    "--------------------------------------------------------"
     "-----------------------\n");
-  for (i=0; i < (long) number_formats; i++)
+  for (i=0; i < (ssize_t) number_formats; i++)
   {
     if (magick_info[i]->stealth != MagickFalse)
       continue;
-    (void) fprintf(file,"%9s%c ",magick_info[i]->name != (char *) NULL ?
-      magick_info[i]->name : "",
+    (void) FormatLocaleFile(file,"%9s%c ",
+      magick_info[i]->name != (char *) NULL ? magick_info[i]->name : "",
       magick_info[i]->blob_support != MagickFalse ? '*' : ' ');
 #if defined(MAGICKCORE_MODULES_SUPPORT)
     {
@@ -973,17 +978,17 @@ MagickExport MagickBooleanType ListMagickInfo(FILE *file,
         (void) CopyMagickString(module,magick_info[i]->module,MaxTextExtent);
       (void) ConcatenateMagickString(module,"          ",MaxTextExtent);
       module[9]='\0';
-      (void) fprintf(file,"%9s ",module);
+      (void) FormatLocaleFile(file,"%9s ",module);
     }
 #endif
-    (void) fprintf(file,"%c%c%c ",magick_info[i]->decoder ? 'r' : '-',
+    (void) FormatLocaleFile(file,"%c%c%c ",magick_info[i]->decoder ? 'r' : '-',
       magick_info[i]->encoder ? 'w' : '-',magick_info[i]->encoder != NULL &&
       magick_info[i]->adjoin != MagickFalse ? '+' : '-');
     if (magick_info[i]->description != (char *) NULL)
-      (void) fprintf(file,"  %s",magick_info[i]->description);
+      (void) FormatLocaleFile(file,"  %s",magick_info[i]->description);
     if (magick_info[i]->version != (char *) NULL)
-      (void) fprintf(file," (%s)",magick_info[i]->version);
-    (void) fprintf(file,"\n");
+      (void) FormatLocaleFile(file," (%s)",magick_info[i]->version);
+    (void) FormatLocaleFile(file,"\n");
     if (magick_info[i]->note != (char *) NULL)
       {
         char
@@ -994,17 +999,17 @@ MagickExport MagickBooleanType ListMagickInfo(FILE *file,
           {
             for (j=0; text[j] != (char *) NULL; j++)
             {
-              (void) fprintf(file,"           %s\n",text[j]);
+              (void) FormatLocaleFile(file,"           %s\n",text[j]);
               text[j]=DestroyString(text[j]);
             }
             text=(char **) RelinquishMagickMemory(text);
           }
       }
   }
-  (void) fprintf(file,"\n* native blob support\n");
-  (void) fprintf(file,"r read support\n");
-  (void) fprintf(file,"w write support\n");
-  (void) fprintf(file,"+ support for multiple images\n");
+  (void) FormatLocaleFile(file,"\n* native blob support\n");
+  (void) FormatLocaleFile(file,"r read support\n");
+  (void) FormatLocaleFile(file,"w write support\n");
+  (void) FormatLocaleFile(file,"+ support for multiple images\n");
   (void) fflush(file);
   magick_info=(const MagickInfo **) RelinquishMagickMemory((void *)
     magick_info);
@@ -1162,6 +1167,30 @@ static void MagickSignalHandler(int signal_number)
   if (signal_handlers[signal_number] != MagickSignalHandler)
     raise(signal_number);
 #endif
+#if defined(SIGQUIT)
+  if (signal_number == SIGQUIT)
+    abort();
+#endif
+#if defined(SIGABRT)
+  if (signal_number == SIGABRT)
+    abort();
+#endif
+#if defined(SIGFPE)
+  if (signal_number == SIGFPE)
+    abort();
+#endif
+#if defined(SIGXCPU)
+  if (signal_number == SIGXCPU)
+    abort();
+#endif
+#if defined(SIGXFSZ)
+  if (signal_number == SIGXFSZ)
+    abort();
+#endif
+#if defined(SIGSEGV)
+  if (signal_number == SIGSEGV)
+    abort();
+#endif
 #if !defined(MAGICKCORE_HAVE__EXIT)
   exit(signal_number);
 #else
@@ -1177,7 +1206,7 @@ static void MagickSignalHandler(int signal_number)
   if (signal_number == SIGTERM)
     exit(signal_number);
 #endif
-  _exit(signal_number);
+  _exit(signal_number);  /* do not invoke registered atexit() methods */
 #endif
 }
 
@@ -1208,6 +1237,12 @@ MagickExport void MagickCoreGenesis(const char *path,
   /*
     Initialize the Magick environment.
   */
+  LockMagickMutex();
+  if (instantiate_magickcore != MagickFalse)
+    {
+      UnlockMagickMutex();
+      return;
+    }
   (void) SemaphoreComponentGenesis();
   (void) LogComponentGenesis();
   (void) LocaleComponentGenesis();
@@ -1255,6 +1290,10 @@ MagickExport void MagickCoreGenesis(const char *path,
       if (signal_handlers[SIGABRT] == (SignalHandler *) NULL)
         signal_handlers[SIGABRT]=RegisterMagickSignalHandler(SIGABRT);
 #endif
+#if defined(SIGSEGV)
+      if (signal_handlers[SIGSEGV] == (SignalHandler *) NULL)
+        signal_handlers[SIGSEGV]=RegisterMagickSignalHandler(SIGSEGV);
+#endif
 #if defined(SIGFPE)
       if (signal_handlers[SIGFPE] == (SignalHandler *) NULL)
         signal_handlers[SIGFPE]=RegisterMagickSignalHandler(SIGFPE);
@@ -1303,9 +1342,12 @@ MagickExport void MagickCoreGenesis(const char *path,
   (void) TypeComponentGenesis();
   (void) MimeComponentGenesis();
   (void) ConstituteComponentGenesis();
+  (void) AnnotateComponentGenesis();
 #if defined(MAGICKCORE_X11_DELEGATE)
   (void) XComponentGenesis();
 #endif
+  instantiate_magickcore=MagickTrue;
+  UnlockMagickMutex();
 }
 \f
 /*
@@ -1328,9 +1370,16 @@ MagickExport void MagickCoreGenesis(const char *path,
 */
 MagickExport void MagickCoreTerminus(void)
 {
+  LockMagickMutex();
+  if (instantiate_magickcore == MagickFalse)
+    {
+      UnlockMagickMutex();
+      return;
+    }
 #if defined(MAGICKCORE_X11_DELEGATE)
   XComponentTerminus();
 #endif
+  AnnotateComponentTerminus();
   ConstituteComponentTerminus();
   MimeComponentTerminus();
   TypeComponentTerminus();
@@ -1357,7 +1406,8 @@ MagickExport void MagickCoreTerminus(void)
   LocaleComponentTerminus();
   LogComponentTerminus();
   SemaphoreComponentTerminus();
-  instantiate_magick=MagickFalse;
+  instantiate_magickcore=MagickFalse;
+  UnlockMagickMutex();
 }
 \f
 /*
@@ -1439,7 +1489,7 @@ MagickExport MagickInfo *SetMagickInfo(const char *name)
 
   assert(name != (const char *) NULL);
   (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",name);
-  magick_info=(MagickInfo *) AcquireAlignedMemory(1,sizeof(*magick_info));
+  magick_info=(MagickInfo *) AcquireMagickMemory(sizeof(*magick_info));
   if (magick_info == (MagickInfo *) NULL)
     ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
   (void) ResetMagickMemory(magick_info,0,sizeof(*magick_info));