]> granicus.if.org Git - imagemagick/blobdiff - MagickCore/exception.c
(no commit message)
[imagemagick] / MagickCore / exception.c
index 47c9d297654592a1eecc2534d40f1e69f9a7424e..3929ba6e3800d26fc7d0affba10776e712a50cc7 100644 (file)
 %                        MagickCore Exception Methods                         %
 %                                                                             %
 %                             Software Design                                 %
-%                               John Cristy                                   %
+%                                  Cristy                                     %
 %                                July 1993                                    %
 %                                                                             %
 %                                                                             %
-%  Copyright 1999-2011 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  %
@@ -231,6 +231,42 @@ MagickExport void CatchException(ExceptionInfo *exception)
 %                                                                             %
 %                                                                             %
 %                                                                             %
+%   C l o n e E x c e p t i o n I n f o                                       %
+%                                                                             %
+%                                                                             %
+%                                                                             %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+%  CloneExceptionInfo() clones the ExceptionInfo structure.
+%
+%  The format of the CloneExceptionInfo method is:
+%
+%      ExceptionInfo *CloneException(ExceptionInfo *exception)
+%
+%  A description of each parameter follows:
+%
+%    o exception: the exception info.
+%
+*/
+MagickExport ExceptionInfo *CloneExceptionInfo(ExceptionInfo *exception)
+{
+  ExceptionInfo
+    *clone_exception;
+
+  clone_exception=(ExceptionInfo *) AcquireMagickMemory(sizeof(*exception));
+  if (clone_exception == (ExceptionInfo *) NULL)
+    ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
+  GetExceptionInfo(clone_exception);
+  InheritException(clone_exception,exception);
+  clone_exception->relinquish=MagickTrue;
+  return(clone_exception);
+}
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%                                                                             %
+%                                                                             %
+%                                                                             %
 +   D e f a u l t E r r o r H a n d l e r                                     %
 %                                                                             %
 %                                                                             %
@@ -289,14 +325,12 @@ static void DefaultErrorHandler(const ExceptionType magick_unused(severity),
 %
 %    o severity: Specifies the numeric error category.
 %
-%    o reason: Specifies the reason to display before terminating the
-%      program.
+%    o reason: Specifies the reason to display before terminating the program.
 %
 %    o description: Specifies any description to the reason.
 %
 */
-static void DefaultFatalErrorHandler(
-  const ExceptionType magick_unused(severity),
+static void DefaultFatalErrorHandler(const ExceptionType severity,
   const char *reason,const char *description)
 {
   if (reason == (char *) NULL)
@@ -307,7 +341,7 @@ static void DefaultFatalErrorHandler(
   (void) FormatLocaleFile(stderr,".\n");
   (void) fflush(stderr);
   MagickCoreTerminus();
-  exit(1);
+  exit((int) (severity-FatalErrorException)+1);
 }
 \f
 /*
@@ -380,7 +414,7 @@ MagickExport ExceptionInfo *DestroyExceptionInfo(ExceptionInfo *exception)
   assert(exception != (ExceptionInfo *) NULL);
   assert(exception->signature == MagickSignature);
   if (exception->semaphore == (SemaphoreInfo *) NULL)
-    AcquireSemaphoreInfo(&exception->semaphore);
+    ActivateSemaphoreInfo(&exception->semaphore);
   LockSemaphoreInfo(exception->semaphore);
   exception->severity=UndefinedException;
   if (exception->exceptions != (void *) NULL)
@@ -390,7 +424,7 @@ MagickExport ExceptionInfo *DestroyExceptionInfo(ExceptionInfo *exception)
   if (exception->relinquish != MagickFalse)
     exception->signature=(~MagickSignature);
   UnlockSemaphoreInfo(exception->semaphore);
-  DestroySemaphoreInfo(&exception->semaphore);
+  RelinquishSemaphoreInfo(&exception->semaphore);
   if (relinquish != MagickFalse)
     exception=(ExceptionInfo *) RelinquishMagickMemory(exception);
   return(exception);
@@ -424,7 +458,7 @@ MagickExport void GetExceptionInfo(ExceptionInfo *exception)
   (void) ResetMagickMemory(exception,0,sizeof(*exception));
   exception->severity=UndefinedException;
   exception->exceptions=(void *) NewLinkedList(0);
-  exception->semaphore=AllocateSemaphoreInfo();
+  exception->semaphore=AcquireSemaphoreInfo();
   exception->signature=MagickSignature;
 }
 \f
@@ -458,7 +492,12 @@ MagickExport char *GetExceptionMessage(const int error)
 
   *exception='\0';
 #if defined(MAGICKCORE_HAVE_STRERROR_R)
+#if !defined(MAGICKCORE_STRERROR_R_CHAR_P)
   (void) strerror_r(error,exception,sizeof(exception));
+#else
+  (void) CopyMagickString(exception,strerror_r(error,exception,
+    sizeof(exception)),sizeof(exception));
+#endif
 #else
   (void) CopyMagickString(exception,strerror(error),sizeof(exception));
 #endif
@@ -620,7 +659,7 @@ MagickExport void InheritException(ExceptionInfo *exception,
   assert(relative->signature == MagickSignature);
   if (relative->exceptions == (void *) NULL)
     return;
-  LockSemaphoreInfo(exception->semaphore);
+  LockSemaphoreInfo(relative->semaphore);
   ResetLinkedListIterator((LinkedListInfo *) relative->exceptions);
   p=(const ExceptionInfo *) GetNextValueInLinkedList((LinkedListInfo *)
     relative->exceptions);
@@ -630,7 +669,7 @@ MagickExport void InheritException(ExceptionInfo *exception,
     p=(const ExceptionInfo *) GetNextValueInLinkedList((LinkedListInfo *)
       relative->exceptions);
   }
-  UnlockSemaphoreInfo(exception->semaphore);
+  UnlockSemaphoreInfo(relative->semaphore);
 }
 \f
 /*
@@ -876,15 +915,22 @@ MagickExport MagickBooleanType ThrowException(ExceptionInfo *exception,
 
   assert(exception != (ExceptionInfo *) NULL);
   assert(exception->signature == MagickSignature);
+  LockSemaphoreInfo(exception->semaphore);
   p=(ExceptionInfo *) GetLastValueInLinkedList((LinkedListInfo *)
     exception->exceptions);
   if ((p != (ExceptionInfo *) NULL) && (p->severity == severity) &&
       (LocaleCompare(exception->reason,reason) == 0) &&
       (LocaleCompare(exception->description,description) == 0))
-    return(MagickTrue);
+    {
+      UnlockSemaphoreInfo(exception->semaphore);
+      return(MagickTrue);
+    }
   p=(ExceptionInfo *) AcquireMagickMemory(sizeof(*p));
   if (p == (ExceptionInfo *) NULL)
-    ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
+    {
+      UnlockSemaphoreInfo(exception->semaphore);
+      ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
+    }
   (void) ResetMagickMemory(p,0,sizeof(*p));
   p->severity=severity;
   if (reason != (const char *) NULL)
@@ -893,9 +939,13 @@ MagickExport MagickBooleanType ThrowException(ExceptionInfo *exception,
     p->description=ConstantString(description);
   p->signature=MagickSignature;
   (void) AppendValueToLinkedList((LinkedListInfo *) exception->exceptions,p);
-  exception->severity=p->severity;
-  exception->reason=p->reason;
-  exception->description=p->description;
+  if (p->severity >= exception->severity)
+    {
+      exception->severity=p->severity;
+      exception->reason=p->reason;
+      exception->description=p->description;
+    }
+  UnlockSemaphoreInfo(exception->semaphore);
   return(MagickTrue);
 }
 \f
@@ -910,8 +960,9 @@ MagickExport MagickBooleanType ThrowException(ExceptionInfo *exception,
 %                                                                             %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
-%  ThrowMagickException logs an exception as determined by the log configuration
-%  file.  If an error occurs, MagickFalse is returned otherwise MagickTrue.
+%  ThrowMagickException logs an exception as determined by the log
+%  configuration file.  If an error occurs, MagickFalse is returned
+%  otherwise MagickTrue.
 %
 %  The format of the ThrowMagickException method is:
 %
@@ -937,10 +988,10 @@ MagickExport MagickBooleanType ThrowException(ExceptionInfo *exception,
 %
 */
 
-static MagickBooleanType ThrowMagickExceptionList(ExceptionInfo *exception,
-  const char *module,const char *function,const size_t line,
-  const ExceptionType severity,const char *tag,const char *format,
-  va_list operands)
+MagickExport MagickBooleanType ThrowMagickExceptionList(
+  ExceptionInfo *exception,const char *module,const char *function,
+  const size_t line,const ExceptionType severity,const char *tag,
+  const char *format,va_list operands)
 {
   char
     message[MaxTextExtent],