From 86e5ac9bd8a1d10f4fc55dae95585db303b6a1e7 Mon Sep 17 00:00:00 2001 From: cristy Date: Sun, 16 Mar 2014 19:27:39 +0000 Subject: [PATCH] --- MagickCore/coder.c | 310 ++++++++++++++++++------------------ MagickCore/color.c | 287 +++++++++++++++++----------------- MagickCore/configure.c | 275 ++++++++++++++++---------------- MagickCore/delegate.c | 207 +++++++++++++------------ MagickCore/locale.c | 237 ++++++++++++++-------------- MagickCore/log.c | 283 +++++++++++++++++---------------- MagickCore/magic.c | 287 +++++++++++++++++----------------- MagickCore/magick.c | 62 ++++---- MagickCore/mime.c | 217 +++++++++++++------------- MagickCore/module.c | 46 +++--- MagickCore/nt-feature.c | 12 +- MagickCore/policy.c | 281 +++++++++++++++++---------------- MagickCore/type.c | 336 +++++++++++++++++++++------------------- 13 files changed, 1433 insertions(+), 1407 deletions(-) diff --git a/MagickCore/coder.c b/MagickCore/coder.c index 9db3547a8..46ef8da79 100644 --- a/MagickCore/coder.c +++ b/MagickCore/coder.c @@ -234,14 +234,129 @@ static SemaphoreInfo *coder_semaphore = (SemaphoreInfo *) NULL; static SplayTreeInfo - *coder_list = (SplayTreeInfo *) NULL; + *coder_cache = (SplayTreeInfo *) NULL; /* Forward declarations. */ static MagickBooleanType IsCoderTreeInstantiated(ExceptionInfo *), - LoadCoderLists(const char *,ExceptionInfo *); + LoadCoderCache(SplayTreeInfo *,const char *,const char *,const size_t, + ExceptionInfo *); + +/* +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% % +% % +% % +% A c q u i r e C o d e r S p l a y T r e e % +% % +% % +% % +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% AcquireCoderCache() caches one or more coder configurations which +% provides a mapping between coder attributes and a coder name. +% +% The format of the AcquireCoderCache coder is: +% +% SplayTreeInfo *AcquireCoderCache(const char *filename, +% ExceptionInfo *exception) +% +% A description of each parameter follows: +% +% o filename: the font file name. +% +% o exception: return any errors or warnings in this structure. +% +*/ + +static void *DestroyCoderNode(void *coder_info) +{ + register CoderInfo + *p; + + p=(CoderInfo *) coder_info; + if (p->exempt == MagickFalse) + { + if (p->path != (char *) NULL) + p->path=DestroyString(p->path); + if (p->name != (char *) NULL) + p->name=DestroyString(p->name); + if (p->magick != (char *) NULL) + p->magick=DestroyString(p->magick); + } + return(RelinquishMagickMemory(p)); +} + +static SplayTreeInfo *AcquireCoderCache(const char *filename, + ExceptionInfo *exception) +{ + const StringInfo + *option; + + LinkedListInfo + *options; + + MagickStatusType + status; + + register ssize_t + i; + + SplayTreeInfo + *coder_cache; + + /* + Load external coder map. + */ + coder_cache=NewSplayTree(CompareSplayTreeString,RelinquishMagickMemory, + DestroyCoderNode); + if (coder_cache == (SplayTreeInfo *) NULL) + ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); + status=MagickTrue; + options=GetConfigureOptions(filename,exception); + option=(const StringInfo *) GetNextValueInLinkedList(options); + while (option != (const StringInfo *) NULL) + { + status&=LoadCoderCache(coder_cache,(const char *) GetStringInfoDatum(option), + GetStringInfoPath(option),0,exception); + option=(const StringInfo *) GetNextValueInLinkedList(options); + } + options=DestroyConfigureOptions(options); + /* + Load built-in coder map. + */ + for (i=0; i < (ssize_t) (sizeof(CoderMap)/sizeof(*CoderMap)); i++) + { + CoderInfo + *coder_info; + + register const CoderMapInfo + *p; + + p=CoderMap+i; + coder_info=(CoderInfo *) AcquireMagickMemory(sizeof(*coder_info)); + if (coder_info == (CoderInfo *) NULL) + { + (void) ThrowMagickException(exception,GetMagickModule(), + ResourceLimitError,"MemoryAllocationFailed","`%s'",p->name); + continue; + } + (void) ResetMagickMemory(coder_info,0,sizeof(*coder_info)); + coder_info->path=(char *) "[built-in]"; + coder_info->magick=(char *) p->magick; + coder_info->name=(char *) p->name; + coder_info->exempt=MagickTrue; + coder_info->signature=MagickSignature; + status&=AddValueToSplayTree(coder_cache,ConstantString(coder_info->magick), + coder_info); + if (status == MagickFalse) + (void) ThrowMagickException(exception,GetMagickModule(), + ResourceLimitError,"MemoryAllocationFailed","`%s'",coder_info->name); + } + return(coder_cache); +} /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -290,8 +405,8 @@ MagickPrivate void CoderComponentTerminus(void) if (coder_semaphore == (SemaphoreInfo *) NULL) ActivateSemaphoreInfo(&coder_semaphore); LockSemaphoreInfo(coder_semaphore); - if (coder_list != (SplayTreeInfo *) NULL) - coder_list=DestroySplayTree(coder_list); + if (coder_cache != (SplayTreeInfo *) NULL) + coder_cache=DestroySplayTree(coder_cache); UnlockSemaphoreInfo(coder_semaphore); RelinquishSemaphoreInfo(&coder_semaphore); } @@ -333,12 +448,12 @@ MagickExport const CoderInfo *GetCoderInfo(const char *name, LockSemaphoreInfo(coder_semaphore); if ((name == (const char *) NULL) || (LocaleCompare(name,"*") == 0)) { - ResetSplayTreeIterator(coder_list); - coder_info=(const CoderInfo *) GetNextValueInSplayTree(coder_list); + ResetSplayTreeIterator(coder_cache); + coder_info=(const CoderInfo *) GetNextValueInSplayTree(coder_cache); UnlockSemaphoreInfo(coder_semaphore); return(coder_info); } - coder_info=(const CoderInfo *) GetValueFromSplayTree(coder_list,name); + coder_info=(const CoderInfo *) GetValueFromSplayTree(coder_cache,name); UnlockSemaphoreInfo(coder_semaphore); return(coder_info); } @@ -406,21 +521,21 @@ MagickExport const CoderInfo **GetCoderInfoList(const char *pattern, if (p == (const CoderInfo *) NULL) return((const CoderInfo **) NULL); coder_map=(const CoderInfo **) AcquireQuantumMemory((size_t) - GetNumberOfNodesInSplayTree(coder_list)+1UL,sizeof(*coder_map)); + GetNumberOfNodesInSplayTree(coder_cache)+1UL,sizeof(*coder_map)); if (coder_map == (const CoderInfo **) NULL) return((const CoderInfo **) NULL); /* Generate coder list. */ LockSemaphoreInfo(coder_semaphore); - ResetSplayTreeIterator(coder_list); - p=(const CoderInfo *) GetNextValueInSplayTree(coder_list); + ResetSplayTreeIterator(coder_cache); + p=(const CoderInfo *) GetNextValueInSplayTree(coder_cache); for (i=0; p != (const CoderInfo *) NULL; ) { if ((p->stealth == MagickFalse) && (GlobExpression(p->name,pattern,MagickFalse) != MagickFalse)) coder_map[i++]=p; - p=(const CoderInfo *) GetNextValueInSplayTree(coder_list); + p=(const CoderInfo *) GetNextValueInSplayTree(coder_cache); } UnlockSemaphoreInfo(coder_semaphore); qsort((void *) coder_map,(size_t) i,sizeof(*coder_map),CoderInfoCompare); @@ -491,21 +606,21 @@ MagickExport char **GetCoderList(const char *pattern, if (p == (const CoderInfo *) NULL) return((char **) NULL); coder_map=(char **) AcquireQuantumMemory((size_t) - GetNumberOfNodesInSplayTree(coder_list)+1UL,sizeof(*coder_map)); + GetNumberOfNodesInSplayTree(coder_cache)+1UL,sizeof(*coder_map)); if (coder_map == (char **) NULL) return((char **) NULL); /* Generate coder list. */ LockSemaphoreInfo(coder_semaphore); - ResetSplayTreeIterator(coder_list); - p=(const CoderInfo *) GetNextValueInSplayTree(coder_list); + ResetSplayTreeIterator(coder_cache); + p=(const CoderInfo *) GetNextValueInSplayTree(coder_cache); for (i=0; p != (const CoderInfo *) NULL; ) { if ((p->stealth == MagickFalse) && (GlobExpression(p->name,pattern,MagickFalse) != MagickFalse)) coder_map[i++]=ConstantString(p->name); - p=(const CoderInfo *) GetNextValueInSplayTree(coder_list); + p=(const CoderInfo *) GetNextValueInSplayTree(coder_cache); } UnlockSemaphoreInfo(coder_semaphore); qsort((void *) coder_map,(size_t) i,sizeof(*coder_map),CoderCompare); @@ -539,13 +654,16 @@ MagickExport char **GetCoderList(const char *pattern, */ static MagickBooleanType IsCoderTreeInstantiated(ExceptionInfo *exception) { - if (coder_semaphore == (SemaphoreInfo *) NULL) - ActivateSemaphoreInfo(&coder_semaphore); - LockSemaphoreInfo(coder_semaphore); - if (coder_list == (SplayTreeInfo *) NULL) - (void) LoadCoderLists(MagickCoderFilename,exception); - UnlockSemaphoreInfo(coder_semaphore); - return(coder_list != (SplayTreeInfo *) NULL ? MagickTrue : MagickFalse); + if (coder_cache == (SplayTreeInfo *) NULL) + { + if (coder_semaphore == (SemaphoreInfo *) NULL) + ActivateSemaphoreInfo(&coder_semaphore); + LockSemaphoreInfo(coder_semaphore); + if (coder_cache == (SplayTreeInfo *) NULL) + (void) AcquireCoderCache(MagickCoderFilename,exception); + UnlockSemaphoreInfo(coder_semaphore); + } + return(coder_cache != (SplayTreeInfo *) NULL ? MagickTrue : MagickFalse); } /* @@ -634,13 +752,14 @@ MagickExport MagickBooleanType ListCoderInfo(FILE *file, % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % -% LoadCoderList() loads the coder configuration file which provides a +% LoadCoderCache() loads the coder configurations which provides a % mapping between coder attributes and a coder name. % -% The format of the LoadCoderList coder is: +% The format of the LoadCoderCache coder is: % -% MagickBooleanType LoadCoderList(const char *xml,const char *filename, -% const size_t depth,ExceptionInfo *exception) +% MagickBooleanType LoadCoderCache(SplayTreeInfo *coder_cache, +% const char *xml,const char *filename,const size_t depth, +% ExceptionInfo *exception) % % A description of each parameter follows: % @@ -653,27 +772,9 @@ MagickExport MagickBooleanType ListCoderInfo(FILE *file, % o exception: return any errors or warnings in this structure. % */ - -static void *DestroyCoderNode(void *coder_info) -{ - register CoderInfo - *p; - - p=(CoderInfo *) coder_info; - if (p->exempt == MagickFalse) - { - if (p->path != (char *) NULL) - p->path=DestroyString(p->path); - if (p->name != (char *) NULL) - p->name=DestroyString(p->name); - if (p->magick != (char *) NULL) - p->magick=DestroyString(p->magick); - } - return(RelinquishMagickMemory(p)); -} - -static MagickBooleanType LoadCoderList(const char *xml,const char *filename, - const size_t depth,ExceptionInfo *exception) +static MagickBooleanType LoadCoderCache(SplayTreeInfo *coder_cache, + const char *xml,const char *filename,const size_t depth, + ExceptionInfo *exception) { char keyword[MaxTextExtent], @@ -695,17 +796,6 @@ static MagickBooleanType LoadCoderList(const char *xml,const char *filename, "Loading coder configuration file \"%s\" ...",filename); if (xml == (const char *) NULL) return(MagickFalse); - if (coder_list == (SplayTreeInfo *) NULL) - { - coder_list=NewSplayTree(CompareSplayTreeString,RelinquishMagickMemory, - DestroyCoderNode); - if (coder_list == (SplayTreeInfo *) NULL) - { - ThrowFileException(exception,ResourceLimitError, - "MemoryAllocationFailed",filename); - return(MagickFalse); - } - } status=MagickTrue; coder_info=(CoderInfo *) NULL; token=AcquireString(xml); @@ -770,7 +860,8 @@ static MagickBooleanType LoadCoderList(const char *xml,const char *filename, xml=FileToString(path,~0UL,exception); if (xml != (char *) NULL) { - status=LoadCoderList(xml,path,depth+1,exception); + status&=LoadCoderCache(coder_cache,xml,path,depth+1, + exception); xml=(char *) RelinquishMagickMemory(xml); } } @@ -796,7 +887,7 @@ static MagickBooleanType LoadCoderList(const char *xml,const char *filename, continue; if (LocaleCompare(keyword,"/>") == 0) { - status=AddValueToSplayTree(coder_list,ConstantString( + status=AddValueToSplayTree(coder_cache,ConstantString( coder_info->magick),coder_info); if (status == MagickFalse) (void) ThrowMagickException(exception,GetMagickModule(), @@ -849,102 +940,3 @@ static MagickBooleanType LoadCoderList(const char *xml,const char *filename, token=(char *) RelinquishMagickMemory(token); return(status); } - -/* -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% % -% % -% % -% L o a d C o d e r L i s t s % -% % -% % -% % -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% -% LoadCoderLists() loads one or more coder configuration file which -% provides a mapping between coder attributes and a coder name. -% -% The format of the LoadCoderLists coder is: -% -% MagickBooleanType LoadCoderLists(const char *filename, -% ExceptionInfo *exception) -% -% A description of each parameter follows: -% -% o filename: the font file name. -% -% o exception: return any errors or warnings in this structure. -% -*/ -static MagickBooleanType LoadCoderLists(const char *filename, - ExceptionInfo *exception) -{ - const StringInfo - *option; - - LinkedListInfo - *options; - - MagickStatusType - status; - - register ssize_t - i; - - /* - Load external coder map. - */ - if (coder_list == (SplayTreeInfo *) NULL) - { - coder_list=NewSplayTree(CompareSplayTreeString,RelinquishMagickMemory, - DestroyCoderNode); - if (coder_list == (SplayTreeInfo *) NULL) - { - ThrowFileException(exception,ResourceLimitError, - "MemoryAllocationFailed",filename); - return(MagickFalse); - } - } - status=MagickTrue; - options=GetConfigureOptions(filename,exception); - option=(const StringInfo *) GetNextValueInLinkedList(options); - while (option != (const StringInfo *) NULL) - { - status&=LoadCoderList((const char *) GetStringInfoDatum(option), - GetStringInfoPath(option),0,exception); - option=(const StringInfo *) GetNextValueInLinkedList(options); - } - options=DestroyConfigureOptions(options); - /* - Load built-in coder map. - */ - for (i=0; i < (ssize_t) (sizeof(CoderMap)/sizeof(*CoderMap)); i++) - { - CoderInfo - *coder_info; - - register const CoderMapInfo - *p; - - p=CoderMap+i; - coder_info=(CoderInfo *) AcquireMagickMemory(sizeof(*coder_info)); - if (coder_info == (CoderInfo *) NULL) - { - (void) ThrowMagickException(exception,GetMagickModule(), - ResourceLimitError,"MemoryAllocationFailed","`%s'",p->name); - continue; - } - (void) ResetMagickMemory(coder_info,0,sizeof(*coder_info)); - coder_info->path=(char *) "[built-in]"; - coder_info->magick=(char *) p->magick; - coder_info->name=(char *) p->name; - coder_info->exempt=MagickTrue; - coder_info->signature=MagickSignature; - status&=AddValueToSplayTree(coder_list,ConstantString(coder_info->magick), - coder_info); - if (status == MagickFalse) - (void) ThrowMagickException(exception,GetMagickModule(), - ResourceLimitError,"MemoryAllocationFailed","`%s'",coder_info->name); - } - return(status != 0 ? MagickTrue : MagickFalse); -} diff --git a/MagickCore/color.c b/MagickCore/color.c index d182058fc..2b8c1df08 100644 --- a/MagickCore/color.c +++ b/MagickCore/color.c @@ -785,7 +785,7 @@ static const ColorMapInfo Static declarations. */ static LinkedListInfo - *color_list = (LinkedListInfo *) NULL; + *color_cache = (LinkedListInfo *) NULL; static SemaphoreInfo *color_semaphore = (SemaphoreInfo *) NULL; @@ -794,8 +794,104 @@ static SemaphoreInfo Forward declarations. */ static MagickBooleanType - IsColorListInstantiated(ExceptionInfo *), - LoadColorLists(const char *,ExceptionInfo *); + IsColorCacheInstantiated(ExceptionInfo *), + LoadColorCache(const char *,const char *,const size_t,ExceptionInfo *); + +/* +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% % +% % +% % +% A c q u i r e C o l o r C a c h e % +% % +% % +% % +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% AcquireColorCache() caches one or more color configurations which provides a +% mapping between color attributes and a color name. +% +% The format of the AcquireColorCache method is: +% +% LinkedListInfo *AcquireColorCache(const char *filename, +% ExceptionInfo *exception) +% +% A description of each parameter follows: +% +% o filename: the font file name. +% +% o exception: return any errors or warnings in this structure. +% +*/ +static LinkedListInfo *AcquireColorCache(const char *filename, + ExceptionInfo *exception) +{ + const StringInfo + *option; + + LinkedListInfo + *color_cache, + *options; + + MagickStatusType + status; + + register ssize_t + i; + + /* + Load external color map. + */ + color_cache=NewLinkedList(0); + if (color_cache == (LinkedListInfo *) NULL) + ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); + status=MagickTrue; + options=GetConfigureOptions(filename,exception); + option=(const StringInfo *) GetNextValueInLinkedList(options); + while (option != (const StringInfo *) NULL) + { + status&=LoadColorCache((const char *) GetStringInfoDatum(option), + GetStringInfoPath(option),0,exception); + option=(const StringInfo *) GetNextValueInLinkedList(options); + } + options=DestroyConfigureOptions(options); + /* + Load built-in color map. + */ + for (i=0; i < (ssize_t) (sizeof(ColorMap)/sizeof(*ColorMap)); i++) + { + ColorInfo + *color_info; + + register const ColorMapInfo + *p; + + p=ColorMap+i; + color_info=(ColorInfo *) AcquireMagickMemory(sizeof(*color_info)); + if (color_info == (ColorInfo *) NULL) + { + (void) ThrowMagickException(exception,GetMagickModule(), + ResourceLimitError,"MemoryAllocationFailed","`%s'",p->name); + continue; + } + (void) ResetMagickMemory(color_info,0,sizeof(*color_info)); + color_info->path=(char *) "[built-in]"; + color_info->name=(char *) p->name; + GetPixelInfo((Image *) NULL,&color_info->color); + color_info->color.red=(double) ScaleCharToQuantum(p->red); + color_info->color.green=(double) ScaleCharToQuantum(p->green); + color_info->color.blue=(double) ScaleCharToQuantum(p->blue); + color_info->color.alpha=(double) (QuantumRange*p->alpha); + color_info->compliance=(ComplianceType) p->compliance; + color_info->exempt=MagickTrue; + color_info->signature=MagickSignature; + status&=AppendValueToLinkedList(color_cache,color_info); + if (IfMagickFalse(status)) + (void) ThrowMagickException(exception,GetMagickModule(), + ResourceLimitError,"MemoryAllocationFailed","`%s'",color_info->name); + } + return(color_cache); +} /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -862,8 +958,8 @@ MagickPrivate void ColorComponentTerminus(void) if (color_semaphore == (SemaphoreInfo *) NULL) ActivateSemaphoreInfo(&color_semaphore); LockSemaphoreInfo(color_semaphore); - if (color_list != (LinkedListInfo *) NULL) - color_list=DestroyLinkedList(color_list,DestroyColorElement); + if (color_cache != (LinkedListInfo *) NULL) + color_cache=DestroyLinkedList(color_cache,DestroyColorElement); UnlockSemaphoreInfo(color_semaphore); RelinquishSemaphoreInfo(&color_semaphore); } @@ -909,8 +1005,8 @@ MagickExport const ColorInfo *GetColorCompliance(const char *name, *q; assert(exception != (ExceptionInfo *) NULL); - if (color_list == (LinkedListInfo *) NULL) - if (IfMagickFalse(IsColorListInstantiated(exception))) + if (color_cache == (LinkedListInfo *) NULL) + if (IfMagickFalse(IsColorCacheInstantiated(exception))) return((const ColorInfo *) NULL); /* Strip names of whitespace. @@ -929,8 +1025,8 @@ MagickExport const ColorInfo *GetColorCompliance(const char *name, Search for color tag. */ LockSemaphoreInfo(color_semaphore); - ResetLinkedListIterator(color_list); - p=(const ColorInfo *) GetNextValueInLinkedList(color_list); + ResetLinkedListIterator(color_cache); + p=(const ColorInfo *) GetNextValueInLinkedList(color_cache); if ((name == (const char *) NULL) || (LocaleCompare(name,"*") == 0)) { UnlockSemaphoreInfo(color_semaphore); @@ -941,14 +1037,14 @@ MagickExport const ColorInfo *GetColorCompliance(const char *name, if (((p->compliance & compliance) != 0) && (LocaleCompare(colorname,p->name) == 0)) break; - p=(const ColorInfo *) GetNextValueInLinkedList(color_list); + p=(const ColorInfo *) GetNextValueInLinkedList(color_cache); } if (p == (ColorInfo *) NULL) (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning, "UnrecognizedColor","`%s'",name); else - (void) InsertValueInLinkedList(color_list,0, - RemoveElementByValueFromLinkedList(color_list,p)); + (void) InsertValueInLinkedList(color_cache,0, + RemoveElementByValueFromLinkedList(color_cache,p)); UnlockSemaphoreInfo(color_semaphore); return(p); } @@ -1189,21 +1285,21 @@ MagickExport const ColorInfo **GetColorInfoList(const char *pattern, if (p == (const ColorInfo *) NULL) return((const ColorInfo **) NULL); colors=(const ColorInfo **) AcquireQuantumMemory((size_t) - GetNumberOfElementsInLinkedList(color_list)+1UL,sizeof(*colors)); + GetNumberOfElementsInLinkedList(color_cache)+1UL,sizeof(*colors)); if (colors == (const ColorInfo **) NULL) return((const ColorInfo **) NULL); /* Generate color list. */ LockSemaphoreInfo(color_semaphore); - ResetLinkedListIterator(color_list); - p=(const ColorInfo *) GetNextValueInLinkedList(color_list); + ResetLinkedListIterator(color_cache); + p=(const ColorInfo *) GetNextValueInLinkedList(color_cache); for (i=0; p != (const ColorInfo *) NULL; ) { if (IsMagickFalse(p->stealth) && IsMagickTrue(GlobExpression(p->name,pattern,MagickFalse))) colors[i++]=p; - p=(const ColorInfo *) GetNextValueInLinkedList(color_list); + p=(const ColorInfo *) GetNextValueInLinkedList(color_cache); } UnlockSemaphoreInfo(color_semaphore); qsort((void *) colors,(size_t) i,sizeof(*colors),ColorInfoCompare); @@ -1282,21 +1378,21 @@ MagickExport char **GetColorList(const char *pattern, if (p == (const ColorInfo *) NULL) return((char **) NULL); colors=(char **) AcquireQuantumMemory((size_t) - GetNumberOfElementsInLinkedList(color_list)+1UL,sizeof(*colors)); + GetNumberOfElementsInLinkedList(color_cache)+1UL,sizeof(*colors)); if (colors == (char **) NULL) return((char **) NULL); /* Generate color list. */ LockSemaphoreInfo(color_semaphore); - ResetLinkedListIterator(color_list); - p=(const ColorInfo *) GetNextValueInLinkedList(color_list); + ResetLinkedListIterator(color_cache); + p=(const ColorInfo *) GetNextValueInLinkedList(color_cache); for (i=0; p != (const ColorInfo *) NULL; ) { if (IsMagickFalse(p->stealth) && IsMagickTrue(GlobExpression(p->name,pattern,MagickFalse))) colors[i++]=ConstantString(p->name); - p=(const ColorInfo *) GetNextValueInLinkedList(color_list); + p=(const ColorInfo *) GetNextValueInLinkedList(color_cache); } UnlockSemaphoreInfo(color_semaphore); qsort((void *) colors,(size_t) i,sizeof(*colors),ColorCompare); @@ -1493,33 +1589,36 @@ MagickExport void GetColorTuple(const PixelInfo *pixel, % % % % % % -+ I s C o l o r L i s t I n s t a n t i a t e d % ++ I s C o l o r C a c h e I n s t a n t i a t e d % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % -% IsColorListInstantiated() determines if the color list is instantiated. If +% IsColorCacheInstantiated() determines if the color list is instantiated. If % not, it instantiates the list and returns it. % % The format of the IsColorInstantiated method is: % -% MagickBooleanType IsColorListInstantiated(ExceptionInfo *exception) +% MagickBooleanType IsColorCacheInstantiated(ExceptionInfo *exception) % % A description of each parameter follows. % % o exception: return any errors or warnings in this structure. % */ -static MagickBooleanType IsColorListInstantiated(ExceptionInfo *exception) +static MagickBooleanType IsColorCacheInstantiated(ExceptionInfo *exception) { - if (color_semaphore == (SemaphoreInfo *) NULL) - ActivateSemaphoreInfo(&color_semaphore); - LockSemaphoreInfo(color_semaphore); - if (color_list == (LinkedListInfo *) NULL) - (void) LoadColorLists(ColorFilename,exception); - UnlockSemaphoreInfo(color_semaphore); - return(color_list != (LinkedListInfo *) NULL ? MagickTrue : MagickFalse); + if (color_cache == (LinkedListInfo *) NULL) + { + if (color_semaphore == (SemaphoreInfo *) NULL) + ActivateSemaphoreInfo(&color_semaphore); + LockSemaphoreInfo(color_semaphore); + if (color_cache == (LinkedListInfo *) NULL) + color_cache=AcquireColorCache(ColorFilename,exception); + UnlockSemaphoreInfo(color_semaphore); + } + return(color_cache != (LinkedListInfo *) NULL ? MagickTrue : MagickFalse); } /* @@ -1800,12 +1899,12 @@ MagickExport MagickBooleanType ListColorInfo(FILE *file, % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % -% LoadColorList() loads the color configuration file which provides a mapping +% LoadColorCache() loads the color configurations which provides a mapping % between color attributes and a color name. % -% The format of the LoadColorList method is: +% The format of the LoadColorCache method is: % -% MagickBooleanType LoadColorList(const char *xml,const char *filename, +% MagickBooleanType LoadColorCache(const char *xml,const char *filename, % const size_t depth,ExceptionInfo *exception) % % A description of each parameter follows: @@ -1819,7 +1918,7 @@ MagickExport MagickBooleanType ListColorInfo(FILE *file, % o exception: return any errors or warnings in this structure. % */ -static MagickBooleanType LoadColorList(const char *xml,const char *filename, +static MagickBooleanType LoadColorCache(const char *xml,const char *filename, const size_t depth,ExceptionInfo *exception) { char @@ -1842,10 +1941,10 @@ static MagickBooleanType LoadColorList(const char *xml,const char *filename, "Loading color file \"%s\" ...",filename); if (xml == (char *) NULL) return(MagickFalse); - if (color_list == (LinkedListInfo *) NULL) + if (color_cache == (LinkedListInfo *) NULL) { - color_list=NewLinkedList(0); - if (color_list == (LinkedListInfo *) NULL) + color_cache=NewLinkedList(0); + if (color_cache == (LinkedListInfo *) NULL) { ThrowFileException(exception,ResourceLimitError, "MemoryAllocationFailed",filename); @@ -1916,7 +2015,7 @@ static MagickBooleanType LoadColorList(const char *xml,const char *filename, xml=FileToString(path,~0UL,exception); if (xml != (char *) NULL) { - status=LoadColorList(xml,path,depth+1,exception); + status=LoadColorCache(xml,path,depth+1,exception); xml=(char *) RelinquishMagickMemory(xml); } } @@ -1942,7 +2041,7 @@ static MagickBooleanType LoadColorList(const char *xml,const char *filename, continue; if (LocaleCompare(keyword,"/>") == 0) { - status=AppendValueToLinkedList(color_list,color_info); + status=AppendValueToLinkedList(color_cache,color_info); if (IfMagickFalse(status)) (void) ThrowMagickException(exception,GetMagickModule(), ResourceLimitError,"MemoryAllocationFailed","`%s'", @@ -2016,108 +2115,6 @@ static MagickBooleanType LoadColorList(const char *xml,const char *filename, % % % % % % -% L o a d C o l o r L i s t s % -% % -% % -% % -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% -% LoadColorList() loads one or more color configuration file which provides a -% mapping between color attributes and a color name. -% -% The format of the LoadColorLists method is: -% -% MagickBooleanType LoadColorLists(const char *filename, -% ExceptionInfo *exception) -% -% A description of each parameter follows: -% -% o filename: the font file name. -% -% o exception: return any errors or warnings in this structure. -% -*/ -static MagickBooleanType LoadColorLists(const char *filename, - ExceptionInfo *exception) -{ - const StringInfo - *option; - - LinkedListInfo - *options; - - MagickStatusType - status; - - register ssize_t - i; - - /* - Load external color map. - */ - if (color_list == (LinkedListInfo *) NULL) - { - color_list=NewLinkedList(0); - if (color_list == (LinkedListInfo *) NULL) - { - ThrowFileException(exception,ResourceLimitError, - "MemoryAllocationFailed",filename); - return(MagickFalse); - } - } - status=MagickTrue; - options=GetConfigureOptions(filename,exception); - option=(const StringInfo *) GetNextValueInLinkedList(options); - while (option != (const StringInfo *) NULL) - { - status&=LoadColorList((const char *) GetStringInfoDatum(option), - GetStringInfoPath(option),0,exception); - option=(const StringInfo *) GetNextValueInLinkedList(options); - } - options=DestroyConfigureOptions(options); - /* - Load built-in color map. - */ - for (i=0; i < (ssize_t) (sizeof(ColorMap)/sizeof(*ColorMap)); i++) - { - ColorInfo - *color_info; - - register const ColorMapInfo - *p; - - p=ColorMap+i; - color_info=(ColorInfo *) AcquireMagickMemory(sizeof(*color_info)); - if (color_info == (ColorInfo *) NULL) - { - (void) ThrowMagickException(exception,GetMagickModule(), - ResourceLimitError,"MemoryAllocationFailed","`%s'",p->name); - continue; - } - (void) ResetMagickMemory(color_info,0,sizeof(*color_info)); - color_info->path=(char *) "[built-in]"; - color_info->name=(char *) p->name; - GetPixelInfo((Image *) NULL,&color_info->color); - color_info->color.red=(double) ScaleCharToQuantum(p->red); - color_info->color.green=(double) ScaleCharToQuantum(p->green); - color_info->color.blue=(double) ScaleCharToQuantum(p->blue); - color_info->color.alpha=(double) (QuantumRange*p->alpha); - color_info->compliance=(ComplianceType) p->compliance; - color_info->exempt=MagickTrue; - color_info->signature=MagickSignature; - status&=AppendValueToLinkedList(color_list,color_info); - if (IfMagickFalse(status)) - (void) ThrowMagickException(exception,GetMagickModule(), - ResourceLimitError,"MemoryAllocationFailed","`%s'",color_info->name); - } - return(status != 0 ? MagickTrue : MagickFalse); -} - -/* -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% % -% % -% % + Q u e r y C o l o r C o m p l i a n c e % % % % % @@ -2524,8 +2521,8 @@ MagickExport MagickBooleanType QueryColorname( return(MagickFalse); alpha=color->alpha_trait == BlendPixelTrait ? color->alpha : OpaqueAlpha; (void) GetColorInfo("*",exception); - ResetLinkedListIterator(color_list); - p=(const ColorInfo *) GetNextValueInLinkedList(color_list); + ResetLinkedListIterator(color_cache); + p=(const ColorInfo *) GetNextValueInLinkedList(color_cache); while (p != (const ColorInfo *) NULL) { if (((p->compliance & compliance) != 0) && @@ -2537,7 +2534,7 @@ MagickExport MagickBooleanType QueryColorname( (void) CopyMagickString(name,p->name,MaxTextExtent); break; } - p=(const ColorInfo *) GetNextValueInLinkedList(color_list); + p=(const ColorInfo *) GetNextValueInLinkedList(color_cache); } return(MagickTrue); } diff --git a/MagickCore/configure.c b/MagickCore/configure.c index 5985d1bbc..563e0c692 100644 --- a/MagickCore/configure.c +++ b/MagickCore/configure.c @@ -107,7 +107,7 @@ static const ConfigureMapInfo }; static LinkedListInfo - *configure_list = (LinkedListInfo *) NULL; + *configure_cache = (LinkedListInfo *) NULL; static SemaphoreInfo *configure_semaphore = (SemaphoreInfo *) NULL; @@ -116,8 +116,101 @@ static SemaphoreInfo Forward declarations. */ static MagickBooleanType - IsConfigureListInstantiated(ExceptionInfo *), - LoadConfigureLists(const char *,ExceptionInfo *); + IsConfigureCacheInstantiated(ExceptionInfo *), + LoadConfigureCache(const char *,const char *,const size_t,ExceptionInfo *); + +/* +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% % +% % +% % +% A c q u i r e C o n f i g u r e C a c h e % +% % +% % +% % +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% AcquireConfigureCache() caches one or more configure configuration files which +% provides a mapping between configure attributes and a configure name. +% +% The format of the AcquireConfigureCache method is: +% +% LinkedListInfo *AcquireConfigureCache(const char *filename, +% ExceptionInfo *exception) +% +% A description of each parameter follows: +% +% o filename: the font file name. +% +% o exception: return any errors or warnings in this structure. +% +*/ +static LinkedListInfo *AcquireConfigureCache(const char *filename, + ExceptionInfo *exception) +{ + const StringInfo + *option; + + LinkedListInfo + *configure_cache, + *options; + + MagickStatusType + status; + + register ssize_t + i; + + /* + Load external configure map. + */ + configure_cache=NewLinkedList(0); + if (configure_cache == (LinkedListInfo *) NULL) + ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); + status=MagickTrue; + options=GetConfigureOptions(filename,exception); + option=(const StringInfo *) GetNextValueInLinkedList(options); + while (option != (const StringInfo *) NULL) + { + status&=LoadConfigureCache((const char *) GetStringInfoDatum(option), + GetStringInfoPath(option),0,exception); + option=(const StringInfo *) GetNextValueInLinkedList(options); + } + options=DestroyConfigureOptions(options); + /* + Load built-in configure map. + */ + for (i=0; i < (ssize_t) (sizeof(ConfigureMap)/sizeof(*ConfigureMap)); i++) + { + ConfigureInfo + *configure_info; + + register const ConfigureMapInfo + *p; + + p=ConfigureMap+i; + configure_info=(ConfigureInfo *) AcquireMagickMemory( + sizeof(*configure_info)); + if (configure_info == (ConfigureInfo *) NULL) + { + (void) ThrowMagickException(exception,GetMagickModule(), + ResourceLimitError,"MemoryAllocationFailed","`%s'",p->name); + continue; + } + (void) ResetMagickMemory(configure_info,0,sizeof(*configure_info)); + configure_info->path=(char *) "[built-in]"; + configure_info->name=(char *) p->name; + configure_info->value=(char *) p->value; + configure_info->exempt=MagickTrue; + configure_info->signature=MagickSignature; + status&=AppendValueToLinkedList(configure_cache,configure_info); + if (status == MagickFalse) + (void) ThrowMagickException(exception,GetMagickModule(), + ResourceLimitError,"MemoryAllocationFailed","`%s'", + configure_info->name); + } + return(configure_cache); +} /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -186,9 +279,9 @@ MagickPrivate void ConfigureComponentTerminus(void) if (configure_semaphore == (SemaphoreInfo *) NULL) ActivateSemaphoreInfo(&configure_semaphore); LockSemaphoreInfo(configure_semaphore); - if (configure_list != (LinkedListInfo *) NULL) - configure_list=DestroyLinkedList(configure_list,DestroyConfigureElement); - configure_list=(LinkedListInfo *) NULL; + if (configure_cache != (LinkedListInfo *) NULL) + configure_cache=DestroyLinkedList(configure_cache,DestroyConfigureElement); + configure_cache=(LinkedListInfo *) NULL; UnlockSemaphoreInfo(configure_semaphore); RelinquishSemaphoreInfo(&configure_semaphore); } @@ -264,14 +357,14 @@ MagickExport const ConfigureInfo *GetConfigureInfo(const char *name, *p; assert(exception != (ExceptionInfo *) NULL); - if (IsConfigureListInstantiated(exception) == MagickFalse) + if (IsConfigureCacheInstantiated(exception) == MagickFalse) return((const ConfigureInfo *) NULL); /* Search for configure tag. */ LockSemaphoreInfo(configure_semaphore); - ResetLinkedListIterator(configure_list); - p=(const ConfigureInfo *) GetNextValueInLinkedList(configure_list); + ResetLinkedListIterator(configure_cache); + p=(const ConfigureInfo *) GetNextValueInLinkedList(configure_cache); if ((name == (const char *) NULL) || (LocaleCompare(name,"*") == 0)) { UnlockSemaphoreInfo(configure_semaphore); @@ -281,11 +374,11 @@ MagickExport const ConfigureInfo *GetConfigureInfo(const char *name, { if (LocaleCompare(name,p->name) == 0) break; - p=(const ConfigureInfo *) GetNextValueInLinkedList(configure_list); + p=(const ConfigureInfo *) GetNextValueInLinkedList(configure_cache); } if (p != (ConfigureInfo *) NULL) - (void) InsertValueInLinkedList(configure_list,0, - RemoveElementByValueFromLinkedList(configure_list,p)); + (void) InsertValueInLinkedList(configure_cache,0, + RemoveElementByValueFromLinkedList(configure_cache,p)); UnlockSemaphoreInfo(configure_semaphore); return(p); } @@ -364,21 +457,21 @@ MagickExport const ConfigureInfo **GetConfigureInfoList(const char *pattern, if (p == (const ConfigureInfo *) NULL) return((const ConfigureInfo **) NULL); options=(const ConfigureInfo **) AcquireQuantumMemory((size_t) - GetNumberOfElementsInLinkedList(configure_list)+1UL,sizeof(*options)); + GetNumberOfElementsInLinkedList(configure_cache)+1UL,sizeof(*options)); if (options == (const ConfigureInfo **) NULL) return((const ConfigureInfo **) NULL); /* Generate configure list. */ LockSemaphoreInfo(configure_semaphore); - ResetLinkedListIterator(configure_list); - p=(const ConfigureInfo *) GetNextValueInLinkedList(configure_list); + ResetLinkedListIterator(configure_cache); + p=(const ConfigureInfo *) GetNextValueInLinkedList(configure_cache); for (i=0; p != (const ConfigureInfo *) NULL; ) { if ((p->stealth == MagickFalse) && (GlobExpression(p->name,pattern,MagickFalse) != MagickFalse)) options[i++]=p; - p=(const ConfigureInfo *) GetNextValueInLinkedList(configure_list); + p=(const ConfigureInfo *) GetNextValueInLinkedList(configure_cache); } UnlockSemaphoreInfo(configure_semaphore); qsort((void *) options,(size_t) i,sizeof(*options),ConfigureInfoCompare); @@ -458,18 +551,18 @@ MagickExport char **GetConfigureList(const char *pattern, if (p == (const ConfigureInfo *) NULL) return((char **) NULL); options=(char **) AcquireQuantumMemory((size_t) - GetNumberOfElementsInLinkedList(configure_list)+1UL,sizeof(*options)); + GetNumberOfElementsInLinkedList(configure_cache)+1UL,sizeof(*options)); if (options == (char **) NULL) return((char **) NULL); LockSemaphoreInfo(configure_semaphore); - ResetLinkedListIterator(configure_list); - p=(const ConfigureInfo *) GetNextValueInLinkedList(configure_list); + ResetLinkedListIterator(configure_cache); + p=(const ConfigureInfo *) GetNextValueInLinkedList(configure_cache); for (i=0; p != (const ConfigureInfo *) NULL; ) { if ((p->stealth == MagickFalse) && (GlobExpression(p->name,pattern,MagickFalse) != MagickFalse)) options[i++]=ConstantString(p->name); - p=(const ConfigureInfo *) GetNextValueInLinkedList(configure_list); + p=(const ConfigureInfo *) GetNextValueInLinkedList(configure_cache); } UnlockSemaphoreInfo(configure_semaphore); qsort((void *) options,(size_t) i,sizeof(*options),ConfigureCompare); @@ -876,33 +969,36 @@ MagickExport const char *GetConfigureValue(const ConfigureInfo *configure_info) % % % % % % -+ I s C o n f i g u r e L i s t I n s t a n t i a t e d % ++ I s C o n f i g u r e C a c h e I n s t a n t i a t e d % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % -% IsConfigureListInstantiated() determines if the configure list is +% IsConfigureCacheInstantiated() determines if the configure list is % instantiated. If not, it instantiates the list and returns it. % % The format of the IsConfigureInstantiated method is: % -% MagickBooleanType IsConfigureListInstantiated(ExceptionInfo *exception) +% MagickBooleanType IsConfigureCacheInstantiated(ExceptionInfo *exception) % % A description of each parameter follows. % % o exception: return any errors or warnings in this structure. % */ -static MagickBooleanType IsConfigureListInstantiated(ExceptionInfo *exception) +static MagickBooleanType IsConfigureCacheInstantiated(ExceptionInfo *exception) { - if (configure_semaphore == (SemaphoreInfo *) NULL) - ActivateSemaphoreInfo(&configure_semaphore); - LockSemaphoreInfo(configure_semaphore); - if (configure_list == (LinkedListInfo *) NULL) - (void) LoadConfigureLists(ConfigureFilename,exception); - UnlockSemaphoreInfo(configure_semaphore); - return(configure_list != (LinkedListInfo *) NULL ? MagickTrue : MagickFalse); + if (configure_cache == (LinkedListInfo *) NULL) + { + if (configure_semaphore == (SemaphoreInfo *) NULL) + ActivateSemaphoreInfo(&configure_semaphore); + LockSemaphoreInfo(configure_semaphore); + if (configure_cache == (LinkedListInfo *) NULL) + configure_cache=AcquireConfigureCache(ConfigureFilename,exception); + UnlockSemaphoreInfo(configure_semaphore); + } + return(configure_cache != (LinkedListInfo *) NULL ? MagickTrue : MagickFalse); } /* @@ -1001,12 +1097,12 @@ MagickExport MagickBooleanType ListConfigureInfo(FILE *file, % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % -% LoadConfigureList() loads the configure configuration file which provides a +% LoadConfigureCache() loads the configure configurations which provides a % mapping between configure attributes and a configure name. % -% The format of the LoadConfigureList method is: +% The format of the LoadConfigureCache method is: % -% MagickBooleanType LoadConfigureList(const char *xml,const char *filename, +% MagickBooleanType LoadConfigureCache(const char *xml,const char *filename, % const size_t depth,ExceptionInfo *exception) % % A description of each parameter follows: @@ -1020,7 +1116,7 @@ MagickExport MagickBooleanType ListConfigureInfo(FILE *file, % o exception: return any errors or warnings in this structure. % */ -static MagickBooleanType LoadConfigureList(const char *xml,const char *filename, +static MagickBooleanType LoadConfigureCache(const char *xml,const char *filename, const size_t depth,ExceptionInfo *exception) { char @@ -1041,10 +1137,10 @@ static MagickBooleanType LoadConfigureList(const char *xml,const char *filename, */ (void) LogMagickEvent(ConfigureEvent,GetMagickModule(), "Loading configure file \"%s\" ...",filename); - if (configure_list == (LinkedListInfo *) NULL) + if (configure_cache == (LinkedListInfo *) NULL) { - configure_list=NewLinkedList(0); - if (configure_list == (LinkedListInfo *) NULL) + configure_cache=NewLinkedList(0); + if (configure_cache == (LinkedListInfo *) NULL) { ThrowFileException(exception,ResourceLimitError, "MemoryAllocationFailed",filename); @@ -1115,7 +1211,7 @@ static MagickBooleanType LoadConfigureList(const char *xml,const char *filename, xml=FileToString(path,~0UL,exception); if (xml != (char *) NULL) { - status=LoadConfigureList(xml,path,depth+1,exception); + status=LoadConfigureCache(xml,path,depth+1,exception); xml=(char *) RelinquishMagickMemory(xml); } } @@ -1142,7 +1238,7 @@ static MagickBooleanType LoadConfigureList(const char *xml,const char *filename, continue; if (LocaleCompare(keyword,"/>") == 0) { - status=AppendValueToLinkedList(configure_list,configure_info); + status=AppendValueToLinkedList(configure_cache,configure_info); if (status == MagickFalse) (void) ThrowMagickException(exception,GetMagickModule(), ResourceLimitError,"MemoryAllocationFailed","`%s'", @@ -1197,102 +1293,3 @@ static MagickBooleanType LoadConfigureList(const char *xml,const char *filename, token=(char *) RelinquishMagickMemory(token); return(status); } - -/* -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% % -% % -% % -% L o a d C o n f i g u r e L i s t s % -% % -% % -% % -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% -% LoadConfigureList() loads one or more configure configuration files which -% provides a mapping between configure attributes and a configure name. -% -% The format of the LoadConfigureLists method is: -% -% MagickBooleanType LoadConfigureLists(const char *filename, -% ExceptionInfo *exception) -% -% A description of each parameter follows: -% -% o filename: the font file name. -% -% o exception: return any errors or warnings in this structure. -% -*/ -static MagickBooleanType LoadConfigureLists(const char *filename, - ExceptionInfo *exception) -{ - const StringInfo - *option; - - LinkedListInfo - *options; - - MagickStatusType - status; - - register ssize_t - i; - - /* - Load external configure map. - */ - if (configure_list == (LinkedListInfo *) NULL) - { - configure_list=NewLinkedList(0); - if (configure_list == (LinkedListInfo *) NULL) - { - ThrowFileException(exception,ResourceLimitError, - "MemoryAllocationFailed",filename); - return(MagickFalse); - } - } - status=MagickTrue; - options=GetConfigureOptions(filename,exception); - option=(const StringInfo *) GetNextValueInLinkedList(options); - while (option != (const StringInfo *) NULL) - { - status&=LoadConfigureList((const char *) GetStringInfoDatum(option), - GetStringInfoPath(option),0,exception); - option=(const StringInfo *) GetNextValueInLinkedList(options); - } - options=DestroyConfigureOptions(options); - /* - Load built-in configure map. - */ - for (i=0; i < (ssize_t) (sizeof(ConfigureMap)/sizeof(*ConfigureMap)); i++) - { - ConfigureInfo - *configure_info; - - register const ConfigureMapInfo - *p; - - p=ConfigureMap+i; - configure_info=(ConfigureInfo *) AcquireMagickMemory( - sizeof(*configure_info)); - if (configure_info == (ConfigureInfo *) NULL) - { - (void) ThrowMagickException(exception,GetMagickModule(), - ResourceLimitError,"MemoryAllocationFailed","`%s'",p->name); - continue; - } - (void) ResetMagickMemory(configure_info,0,sizeof(*configure_info)); - configure_info->path=(char *) "[built-in]"; - configure_info->name=(char *) p->name; - configure_info->value=(char *) p->value; - configure_info->exempt=MagickTrue; - configure_info->signature=MagickSignature; - status&=AppendValueToLinkedList(configure_list,configure_info); - if (status == MagickFalse) - (void) ThrowMagickException(exception,GetMagickModule(), - ResourceLimitError,"MemoryAllocationFailed","`%s'", - configure_info->name); - } - return(status != 0 ? MagickTrue : MagickFalse); -} diff --git a/MagickCore/delegate.c b/MagickCore/delegate.c index ce6d84e7d..7d390f028 100644 --- a/MagickCore/delegate.c +++ b/MagickCore/delegate.c @@ -129,7 +129,7 @@ static const char Global declaractions. */ static LinkedListInfo - *delegate_list = (LinkedListInfo *) NULL; + *delegate_cache = (LinkedListInfo *) NULL; static SemaphoreInfo *delegate_semaphore = (SemaphoreInfo *) NULL; @@ -138,8 +138,70 @@ static SemaphoreInfo Forward declaractions. */ static MagickBooleanType - IsDelegateListInstantiated(ExceptionInfo *), - LoadDelegateLists(const char *,ExceptionInfo *); + IsDelegateCacheInstantiated(ExceptionInfo *), + LoadDelegateCache(const char *,const char *,const size_t,ExceptionInfo *); + +/* +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% % +% % +% % +% A c q u i r e D e l e g a t e C a c h e % +% % +% % +% % +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% AcquireDelegateCache() caches one or more delegate configurations which +% provides a mapping between delegate attributes and a delegate name. +% +% The format of the AcquireDelegateCache method is: +% +% LinkedListInfo *AcquireDelegateCache(const char *filename, +% ExceptionInfo *exception) +% +% A description of each parameter follows: +% +% o filename: the font file name. +% +% o exception: return any errors or warnings in this structure. +% +*/ +static LinkedListInfo *AcquireDelegateCache(const char *filename, + ExceptionInfo *exception) +{ +#if defined(MAGICKCORE_ZERO_CONFIGURATION_SUPPORT) + return(LoadDelegateCache(DelegateMap,"built-in",0,exception)); +#else + const StringInfo + *option; + + LinkedListInfo + *delegate_cache, + *options; + + MagickStatusType + status; + + delegate_cache=NewLinkedList(0); + if (delegate_cache == (LinkedListInfo *) NULL) + ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); + status=MagickTrue; + options=GetConfigureOptions(filename,exception); + option=(const StringInfo *) GetNextValueInLinkedList(options); + while (option != (const StringInfo *) NULL) + { + status&=LoadDelegateCache((const char *) GetStringInfoDatum(option), + GetStringInfoPath(option),0,exception); + option=(const StringInfo *) GetNextValueInLinkedList(options); + } + options=DestroyConfigureOptions(options); + if ((delegate_cache == (LinkedListInfo *) NULL) || + (IfMagickTrue(IsLinkedListEmpty(delegate_cache)))) + status&=LoadDelegateCache(DelegateMap,"built-in",0,exception); + return(delegate_cache); +#endif +} /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -207,8 +269,8 @@ MagickPrivate void DelegateComponentTerminus(void) if (delegate_semaphore == (SemaphoreInfo *) NULL) ActivateSemaphoreInfo(&delegate_semaphore); LockSemaphoreInfo(delegate_semaphore); - if (delegate_list != (LinkedListInfo *) NULL) - delegate_list=DestroyLinkedList(delegate_list,DestroyDelegate); + if (delegate_cache != (LinkedListInfo *) NULL) + delegate_cache=DestroyLinkedList(delegate_cache,DestroyDelegate); UnlockSemaphoreInfo(delegate_semaphore); RelinquishSemaphoreInfo(&delegate_semaphore); } @@ -366,15 +428,15 @@ MagickExport const DelegateInfo *GetDelegateInfo(const char *decode, *p; assert(exception != (ExceptionInfo *) NULL); - if (delegate_list == (LinkedListInfo *) NULL) - if( IfMagickFalse(IsDelegateListInstantiated(exception)) ) + if (delegate_cache == (LinkedListInfo *) NULL) + if( IfMagickFalse(IsDelegateCacheInstantiated(exception)) ) return((const DelegateInfo *) NULL); /* Search for named delegate. */ LockSemaphoreInfo(delegate_semaphore); - ResetLinkedListIterator(delegate_list); - p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_list); + ResetLinkedListIterator(delegate_cache); + p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_cache); if ((LocaleCompare(decode,"*") == 0) && (LocaleCompare(encode,"*") == 0)) { UnlockSemaphoreInfo(delegate_semaphore); @@ -386,14 +448,14 @@ MagickExport const DelegateInfo *GetDelegateInfo(const char *decode, { if (LocaleCompare(p->decode,decode) == 0) break; - p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_list); + p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_cache); continue; } if (p->mode < 0) { if (LocaleCompare(p->encode,encode) == 0) break; - p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_list); + p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_cache); continue; } if (LocaleCompare(decode,p->decode) == 0) @@ -405,11 +467,11 @@ MagickExport const DelegateInfo *GetDelegateInfo(const char *decode, if (LocaleCompare(decode,p->decode) == 0) if (LocaleCompare(encode,"*") == 0) break; - p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_list); + p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_cache); } if (p != (const DelegateInfo *) NULL) - (void) InsertValueInLinkedList(delegate_list,0, - RemoveElementByValueFromLinkedList(delegate_list,p)); + (void) InsertValueInLinkedList(delegate_cache,0, + RemoveElementByValueFromLinkedList(delegate_cache,p)); UnlockSemaphoreInfo(delegate_semaphore); return(p); } @@ -496,22 +558,22 @@ MagickExport const DelegateInfo **GetDelegateInfoList(const char *pattern, if (p == (const DelegateInfo *) NULL) return((const DelegateInfo **) NULL); delegates=(const DelegateInfo **) AcquireQuantumMemory((size_t) - GetNumberOfElementsInLinkedList(delegate_list)+1UL,sizeof(*delegates)); + GetNumberOfElementsInLinkedList(delegate_cache)+1UL,sizeof(*delegates)); if (delegates == (const DelegateInfo **) NULL) return((const DelegateInfo **) NULL); /* Generate delegate list. */ LockSemaphoreInfo(delegate_semaphore); - ResetLinkedListIterator(delegate_list); - p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_list); + ResetLinkedListIterator(delegate_cache); + p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_cache); for (i=0; p != (const DelegateInfo *) NULL; ) { if( IfMagickFalse(p->stealth) && ( IfMagickTrue(GlobExpression(p->decode,pattern,MagickFalse)) || IfMagickTrue(GlobExpression(p->encode,pattern,MagickFalse))) ) delegates[i++]=p; - p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_list); + p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_cache); } UnlockSemaphoreInfo(delegate_semaphore); qsort((void *) delegates,(size_t) i,sizeof(*delegates),DelegateInfoCompare); @@ -593,12 +655,12 @@ MagickExport char **GetDelegateList(const char *pattern, if (p == (const DelegateInfo *) NULL) return((char **) NULL); delegates=(char **) AcquireQuantumMemory((size_t) - GetNumberOfElementsInLinkedList(delegate_list)+1UL,sizeof(*delegates)); + GetNumberOfElementsInLinkedList(delegate_cache)+1UL,sizeof(*delegates)); if (delegates == (char **) NULL) return((char **) NULL); LockSemaphoreInfo(delegate_semaphore); - ResetLinkedListIterator(delegate_list); - p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_list); + ResetLinkedListIterator(delegate_cache); + p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_cache); for (i=0; p != (const DelegateInfo *) NULL; ) { if( IfMagickFalse(p->stealth) && @@ -607,7 +669,7 @@ MagickExport char **GetDelegateList(const char *pattern, if( IfMagickFalse(p->stealth) && IfMagickTrue(GlobExpression(p->encode,pattern,MagickFalse)) ) delegates[i++]=ConstantString(p->encode); - p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_list); + p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_cache); } UnlockSemaphoreInfo(delegate_semaphore); qsort((void *) delegates,(size_t) i,sizeof(*delegates),DelegateCompare); @@ -686,33 +748,36 @@ MagickExport MagickBooleanType GetDelegateThreadSupport( % % % % % % -+ I s D e l e g a t e L i s t I n s t a n t i a t e d % ++ I s D e l e g a t e C a c h e I n s t a n t i a t e d % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % -% IsDelegateListInstantiated() determines if the delegate list is instantiated. +% IsDelegateCacheInstantiated() determines if the delegate list is instantiated. % If not, it instantiates the list and returns it. % % The format of the IsDelegateInstantiated method is: % -% MagickBooleanType IsDelegateListInstantiated(ExceptionInfo *exception) +% MagickBooleanType IsDelegateCacheInstantiated(ExceptionInfo *exception) % % A description of each parameter follows. % % o exception: return any errors or warnings in this structure. % */ -static MagickBooleanType IsDelegateListInstantiated(ExceptionInfo *exception) +static MagickBooleanType IsDelegateCacheInstantiated(ExceptionInfo *exception) { - if (delegate_semaphore == (SemaphoreInfo *) NULL) - ActivateSemaphoreInfo(&delegate_semaphore); - LockSemaphoreInfo(delegate_semaphore); - if (delegate_list == (LinkedListInfo *) NULL) - (void) LoadDelegateLists(DelegateFilename,exception); - UnlockSemaphoreInfo(delegate_semaphore); - return(IsMagickNotNULL(delegate_list)); + if (delegate_cache == (LinkedListInfo *) NULL) + { + if (delegate_semaphore == (SemaphoreInfo *) NULL) + ActivateSemaphoreInfo(&delegate_semaphore); + LockSemaphoreInfo(delegate_semaphore); + if (delegate_cache == (LinkedListInfo *) NULL) + delegate_cache=AcquireDelegateCache(DelegateFilename,exception); + UnlockSemaphoreInfo(delegate_semaphore); + } + return(IsMagickNotNULL(delegate_cache)); } /* @@ -1184,12 +1249,12 @@ MagickExport MagickBooleanType ListDelegateInfo(FILE *file, % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % -% LoadDelegateList() loads the delegate configuration file which provides a +% LoadDelegateCache() loads the delegate configurations which provides a % mapping between delegate attributes and a delegate name. % -% The format of the LoadDelegateList method is: +% The format of the LoadDelegateCache method is: % -% MagickBooleanType LoadDelegateList(const char *xml,const char *filename, +% MagickBooleanType LoadDelegateCache(const char *xml,const char *filename, % const size_t depth,ExceptionInfo *exception) % % A description of each parameter follows: @@ -1203,7 +1268,7 @@ MagickExport MagickBooleanType ListDelegateInfo(FILE *file, % o exception: return any errors or warnings in this structure. % */ -static MagickBooleanType LoadDelegateList(const char *xml,const char *filename, +static MagickBooleanType LoadDelegateCache(const char *xml,const char *filename, const size_t depth,ExceptionInfo *exception) { char @@ -1226,10 +1291,10 @@ static MagickBooleanType LoadDelegateList(const char *xml,const char *filename, "Loading delegate configuration file \"%s\" ...",filename); if (xml == (const char *) NULL) return(MagickFalse); - if (delegate_list == (LinkedListInfo *) NULL) + if (delegate_cache == (LinkedListInfo *) NULL) { - delegate_list=NewLinkedList(0); - if (delegate_list == (LinkedListInfo *) NULL) + delegate_cache=NewLinkedList(0); + if (delegate_cache == (LinkedListInfo *) NULL) { ThrowFileException(exception,ResourceLimitError, "MemoryAllocationFailed",filename); @@ -1300,7 +1365,7 @@ static MagickBooleanType LoadDelegateList(const char *xml,const char *filename, xml=FileToString(path,~0UL,exception); if (xml != (char *) NULL) { - status=LoadDelegateList(xml,path,depth+1,exception); + status=LoadDelegateCache(xml,path,depth+1,exception); xml=(char *) RelinquishMagickMemory(xml); } } @@ -1326,7 +1391,7 @@ static MagickBooleanType LoadDelegateList(const char *xml,const char *filename, continue; if (LocaleCompare(keyword,"/>") == 0) { - status=AppendValueToLinkedList(delegate_list,delegate_info); + status=AppendValueToLinkedList(delegate_cache,delegate_info); if( IfMagickFalse(status) ) (void) ThrowMagickException(exception,GetMagickModule(), ResourceLimitError,"MemoryAllocationFailed","`%s'", @@ -1440,61 +1505,3 @@ static MagickBooleanType LoadDelegateList(const char *xml,const char *filename, token=(char *) RelinquishMagickMemory(token); return(status); } - -/* -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% % -% % -% % -% L o a d D e l e g a t e L i s t s % -% % -% % -% % -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% -% LoadDelegateList() loads one or more delegate configuration file which -% provides a mapping between delegate attributes and a delegate name. -% -% The format of the LoadDelegateLists method is: -% -% MagickBooleanType LoadDelegateLists(const char *filename, -% ExceptionInfo *exception) -% -% A description of each parameter follows: -% -% o filename: the font file name. -% -% o exception: return any errors or warnings in this structure. -% -*/ -static MagickBooleanType LoadDelegateLists(const char *filename, - ExceptionInfo *exception) -{ -#if defined(MAGICKCORE_ZERO_CONFIGURATION_SUPPORT) - return(LoadDelegateList(DelegateMap,"built-in",0,exception)); -#else - const StringInfo - *option; - - LinkedListInfo - *options; - - MagickStatusType - status; - - status=MagickFalse; - options=GetConfigureOptions(filename,exception); - option=(const StringInfo *) GetNextValueInLinkedList(options); - while (option != (const StringInfo *) NULL) - { - status&=LoadDelegateList((const char *) GetStringInfoDatum(option), - GetStringInfoPath(option),0,exception); - option=(const StringInfo *) GetNextValueInLinkedList(options); - } - options=DestroyConfigureOptions(options); - if ((delegate_list == (LinkedListInfo *) NULL) || - (IfMagickTrue(IsLinkedListEmpty(delegate_list)))) - status&=LoadDelegateList(DelegateMap,"built-in",0,exception); - return(IsMagickTrue(status!=0)); -#endif -} diff --git a/MagickCore/locale.c b/MagickCore/locale.c index 2f1452c58..33312702d 100644 --- a/MagickCore/locale.c +++ b/MagickCore/locale.c @@ -93,7 +93,7 @@ static SemaphoreInfo *locale_semaphore = (SemaphoreInfo *) NULL; static SplayTreeInfo - *locale_list = (SplayTreeInfo *) NULL; + *locale_cache = (SplayTreeInfo *) NULL; #if defined(MAGICKCORE_HAVE_STRTOD_L) static volatile locale_t @@ -105,7 +105,8 @@ static volatile locale_t */ static MagickBooleanType IsLocaleTreeInstantiated(ExceptionInfo *), - LoadLocaleLists(const char *,const char *,ExceptionInfo *); + LoadLocaleCache(const char *,const char *,const char *,const size_t, + ExceptionInfo *); #if defined(MAGICKCORE_HAVE_STRTOD_L) /* @@ -140,6 +141,102 @@ static locale_t AcquireCLocale(void) } #endif +/* +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% % +% % +% % +% A c q u i r e L o c a l e S p l a y T r e e % +% % +% % +% % +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% AcquireLocaleSplayTree() caches one or more locale configurations which +% provides a mapping between locale attributes and a locale tag. +% +% The format of the AcquireLocaleSplayTree method is: +% +% SplayTreeInfo *AcquireLocaleSplayTree(const char *filename, +% ExceptionInfo *exception) +% +% A description of each parameter follows: +% +% o filename: the font file tag. +% +% o locale: the actual locale. +% +% o exception: return any errors or warnings in this structure. +% +*/ + +static void *DestroyLocaleNode(void *locale_info) +{ + register LocaleInfo + *p; + + p=(LocaleInfo *) locale_info; + if (p->path != (char *) NULL) + p->path=DestroyString(p->path); + if (p->tag != (char *) NULL) + p->tag=DestroyString(p->tag); + if (p->message != (char *) NULL) + p->message=DestroyString(p->message); + return(RelinquishMagickMemory(p)); +} + +static SplayTreeInfo *AcquireLocaleSplayTree(const char *filename, + const char *locale,ExceptionInfo *exception) +{ +#if defined(MAGICKCORE_ZERO_CONFIGURATION_SUPPORT) + return(LoadLocaleCache(LocaleMap,"built-in",locale,0,exception)); +#else + const StringInfo + *option; + + LinkedListInfo + *options; + + MagickStatusType + status; + + SplayTreeInfo + *locale_cache; + + locale_cache=NewSplayTree(CompareSplayTreeString,(void *(*)(void *)) NULL, + DestroyLocaleNode); + if (locale_cache == (SplayTreeInfo *) NULL) + ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); + status=MagickTrue; + options=GetLocaleOptions(filename,exception); + option=(const StringInfo *) GetNextValueInLinkedList(options); + while (option != (const StringInfo *) NULL) + { + status&=LoadLocaleCache((const char *) GetStringInfoDatum(option), + GetStringInfoPath(option),locale,0,exception); + option=(const StringInfo *) GetNextValueInLinkedList(options); + } + options=DestroyLocaleOptions(options); + if ((locale_cache == (SplayTreeInfo *) NULL) || + (GetNumberOfNodesInSplayTree(locale_cache) == 0)) + { + options=GetLocaleOptions("english.xml",exception); + option=(const StringInfo *) GetNextValueInLinkedList(options); + while (option != (const StringInfo *) NULL) + { + status&=LoadLocaleCache((const char *) GetStringInfoDatum(option), + GetStringInfoPath(option),locale,0,exception); + option=(const StringInfo *) GetNextValueInLinkedList(options); + } + options=DestroyLocaleOptions(options); + } + if ((locale_cache == (SplayTreeInfo *) NULL) || + (GetNumberOfNodesInSplayTree(locale_cache) == 0)) + status&=LoadLocaleCache(LocaleMap,"built-in",locale,0,exception); + return(locale_cache); +#endif +} + #if defined(MAGICKCORE_HAVE_STRTOD_L) /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -429,12 +526,12 @@ MagickExport const LocaleInfo *GetLocaleInfo_(const char *tag, LockSemaphoreInfo(locale_semaphore); if ((tag == (const char *) NULL) || (LocaleCompare(tag,"*") == 0)) { - ResetSplayTreeIterator(locale_list); - locale_info=(const LocaleInfo *) GetNextValueInSplayTree(locale_list); + ResetSplayTreeIterator(locale_cache); + locale_info=(const LocaleInfo *) GetNextValueInSplayTree(locale_cache); UnlockSemaphoreInfo(locale_semaphore); return(locale_info); } - locale_info=(const LocaleInfo *) GetValueFromSplayTree(locale_list,tag); + locale_info=(const LocaleInfo *) GetValueFromSplayTree(locale_cache,tag); UnlockSemaphoreInfo(locale_semaphore); return(locale_info); } @@ -513,21 +610,21 @@ MagickExport const LocaleInfo **GetLocaleInfoList(const char *pattern, if (p == (const LocaleInfo *) NULL) return((const LocaleInfo **) NULL); messages=(const LocaleInfo **) AcquireQuantumMemory((size_t) - GetNumberOfNodesInSplayTree(locale_list)+1UL,sizeof(*messages)); + GetNumberOfNodesInSplayTree(locale_cache)+1UL,sizeof(*messages)); if (messages == (const LocaleInfo **) NULL) return((const LocaleInfo **) NULL); /* Generate locale list. */ LockSemaphoreInfo(locale_semaphore); - ResetSplayTreeIterator(locale_list); - p=(const LocaleInfo *) GetNextValueInSplayTree(locale_list); + ResetSplayTreeIterator(locale_cache); + p=(const LocaleInfo *) GetNextValueInSplayTree(locale_cache); for (i=0; p != (const LocaleInfo *) NULL; ) { if ((p->stealth == MagickFalse) && (GlobExpression(p->tag,pattern,MagickTrue) != MagickFalse)) messages[i++]=p; - p=(const LocaleInfo *) GetNextValueInSplayTree(locale_list); + p=(const LocaleInfo *) GetNextValueInSplayTree(locale_cache); } UnlockSemaphoreInfo(locale_semaphore); qsort((void *) messages,(size_t) i,sizeof(*messages),LocaleInfoCompare); @@ -608,17 +705,17 @@ MagickExport char **GetLocaleList(const char *pattern, if (p == (const LocaleInfo *) NULL) return((char **) NULL); messages=(char **) AcquireQuantumMemory((size_t) - GetNumberOfNodesInSplayTree(locale_list)+1UL,sizeof(*messages)); + GetNumberOfNodesInSplayTree(locale_cache)+1UL,sizeof(*messages)); if (messages == (char **) NULL) return((char **) NULL); LockSemaphoreInfo(locale_semaphore); - p=(const LocaleInfo *) GetNextValueInSplayTree(locale_list); + p=(const LocaleInfo *) GetNextValueInSplayTree(locale_cache); for (i=0; p != (const LocaleInfo *) NULL; ) { if ((p->stealth == MagickFalse) && (GlobExpression(p->tag,pattern,MagickTrue) != MagickFalse)) messages[i++]=ConstantString(p->tag); - p=(const LocaleInfo *) GetNextValueInSplayTree(locale_list); + p=(const LocaleInfo *) GetNextValueInSplayTree(locale_cache); } UnlockSemaphoreInfo(locale_semaphore); qsort((void *) messages,(size_t) i,sizeof(*messages),LocaleTagCompare); @@ -817,7 +914,7 @@ static MagickBooleanType IsLocaleTreeInstantiated(ExceptionInfo *exception) if (locale_semaphore == (SemaphoreInfo *) NULL) ActivateSemaphoreInfo(&locale_semaphore); LockSemaphoreInfo(locale_semaphore); - if (locale_list == (SplayTreeInfo *) NULL) + if (locale_cache == (SplayTreeInfo *) NULL) { char *locale; @@ -839,11 +936,11 @@ static MagickBooleanType IsLocaleTreeInstantiated(ExceptionInfo *exception) locale=GetEnvironmentValue("LANG"); if (locale == (char *) NULL) locale=ConstantString("C"); - (void) LoadLocaleLists(LocaleFilename,locale,exception); + locale_cache=AcquireLocaleSplayTree(LocaleFilename,locale,exception); locale=DestroyString(locale); } UnlockSemaphoreInfo(locale_semaphore); - return(locale_list != (SplayTreeInfo *) NULL ? MagickTrue : MagickFalse); + return(locale_cache != (SplayTreeInfo *) NULL ? MagickTrue : MagickFalse); } /* @@ -989,12 +1086,12 @@ MagickExport MagickBooleanType ListLocaleInfo(FILE *file, % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % -% LoadLocaleList() loads the locale configuration file which provides a mapping +% LoadLocaleCache() loads the locale configurations which provides a mapping % between locale attributes and a locale name. % -% The format of the LoadLocaleList method is: +% The format of the LoadLocaleCache method is: % -% MagickBooleanType LoadLocaleList(const char *xml,const char *filename, +% MagickBooleanType LoadLocaleCache(const char *xml,const char *filename, % const size_t depth,ExceptionInfo *exception) % % A description of each parameter follows: @@ -1032,21 +1129,6 @@ static void ChopLocaleComponents(char *path,const size_t components) *path='\0'; } -static void *DestroyLocaleNode(void *locale_info) -{ - register LocaleInfo - *p; - - p=(LocaleInfo *) locale_info; - if (p->path != (char *) NULL) - p->path=DestroyString(p->path); - if (p->tag != (char *) NULL) - p->tag=DestroyString(p->tag); - if (p->message != (char *) NULL) - p->message=DestroyString(p->message); - return(RelinquishMagickMemory(p)); -} - static void LocaleFatalErrorHandler( const ExceptionType magick_unused(severity), const char *reason,const char *description) @@ -1068,7 +1150,7 @@ static inline size_t MagickMin(const size_t x,const size_t y) return(y); } -static MagickBooleanType LoadLocaleList(const char *xml,const char *filename, +static MagickBooleanType LoadLocaleCache(const char *xml,const char *filename, const char *locale,const size_t depth,ExceptionInfo *exception) { char @@ -1099,11 +1181,11 @@ static MagickBooleanType LoadLocaleList(const char *xml,const char *filename, "Loading locale configure file \"%s\" ...",filename); if (xml == (const char *) NULL) return(MagickFalse); - if (locale_list == (SplayTreeInfo *) NULL) + if (locale_cache == (SplayTreeInfo *) NULL) { - locale_list=NewSplayTree(CompareSplayTreeString,(void *(*)(void *)) NULL, + locale_cache=NewSplayTree(CompareSplayTreeString,(void *(*)(void *)) NULL, DestroyLocaleNode); - if (locale_list == (SplayTreeInfo *) NULL) + if (locale_cache == (SplayTreeInfo *) NULL) return(MagickFalse); } status=MagickTrue; @@ -1189,7 +1271,7 @@ static MagickBooleanType LoadLocaleList(const char *xml,const char *filename, xml=FileToString(path,~0UL,exception); if (xml != (char *) NULL) { - status=LoadLocaleList(xml,path,locale,depth+1,exception); + status=LoadLocaleCache(xml,path,locale,depth+1,exception); xml=(char *) RelinquishMagickMemory(xml); } } @@ -1256,7 +1338,7 @@ static MagickBooleanType LoadLocaleList(const char *xml,const char *filename, locale_info->tag=ConstantString(tag); locale_info->message=ConstantString(message); locale_info->signature=MagickSignature; - status=AddValueToSplayTree(locale_list,locale_info->tag,locale_info); + status=AddValueToSplayTree(locale_cache,locale_info->tag,locale_info); if (status == MagickFalse) (void) ThrowMagickException(exception,GetMagickModule(), ResourceLimitError,"MemoryAllocationFailed","`%s'", @@ -1306,79 +1388,6 @@ static MagickBooleanType LoadLocaleList(const char *xml,const char *filename, % % % % % % -% L o a d L o c a l e L i s t s % -% % -% % -% % -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% -% LoadLocaleList() loads one or more locale configuration file which -% provides a mapping between locale attributes and a locale tag. -% -% The format of the LoadLocaleLists method is: -% -% MagickBooleanType LoadLocaleLists(const char *filename, -% ExceptionInfo *exception) -% -% A description of each parameter follows: -% -% o filename: the font file tag. -% -% o locale: the actual locale. -% -% o exception: return any errors or warnings in this structure. -% -*/ -static MagickBooleanType LoadLocaleLists(const char *filename, - const char *locale,ExceptionInfo *exception) -{ -#if defined(MAGICKCORE_ZERO_CONFIGURATION_SUPPORT) - return(LoadLocaleList(LocaleMap,"built-in",locale,0,exception)); -#else - const StringInfo - *option; - - LinkedListInfo - *options; - - MagickStatusType - status; - - status=MagickFalse; - options=GetLocaleOptions(filename,exception); - option=(const StringInfo *) GetNextValueInLinkedList(options); - while (option != (const StringInfo *) NULL) - { - status&=LoadLocaleList((const char *) GetStringInfoDatum(option), - GetStringInfoPath(option),locale,0,exception); - option=(const StringInfo *) GetNextValueInLinkedList(options); - } - options=DestroyLocaleOptions(options); - if ((locale_list == (SplayTreeInfo *) NULL) || - (GetNumberOfNodesInSplayTree(locale_list) == 0)) - { - options=GetLocaleOptions("english.xml",exception); - option=(const StringInfo *) GetNextValueInLinkedList(options); - while (option != (const StringInfo *) NULL) - { - status&=LoadLocaleList((const char *) GetStringInfoDatum(option), - GetStringInfoPath(option),locale,0,exception); - option=(const StringInfo *) GetNextValueInLinkedList(options); - } - options=DestroyLocaleOptions(options); - } - if ((locale_list == (SplayTreeInfo *) NULL) || - (GetNumberOfNodesInSplayTree(locale_list) == 0)) - status&=LoadLocaleList(LocaleMap,"built-in",locale,0,exception); - return(status != 0 ? MagickTrue : MagickFalse); -#endif -} - -/* -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% % -% % -% % + L o c a l e C o m p o n e n t G e n e s i s % % % % % @@ -1421,8 +1430,8 @@ MagickPrivate void LocaleComponentTerminus(void) if (locale_semaphore == (SemaphoreInfo *) NULL) ActivateSemaphoreInfo(&locale_semaphore); LockSemaphoreInfo(locale_semaphore); - if (locale_list != (SplayTreeInfo *) NULL) - locale_list=DestroySplayTree(locale_list); + if (locale_cache != (SplayTreeInfo *) NULL) + locale_cache=DestroySplayTree(locale_cache); #if defined(MAGICKCORE_HAVE_STRTOD_L) DestroyCLocale(); #endif diff --git a/MagickCore/log.c b/MagickCore/log.c index 0ebd2b816..c7b3051ec 100644 --- a/MagickCore/log.c +++ b/MagickCore/log.c @@ -181,7 +181,7 @@ static char log_name[MaxTextExtent] = "Magick"; static LinkedListInfo - *log_list = (LinkedListInfo *) NULL; + *log_cache = (LinkedListInfo *) NULL; static SemaphoreInfo *event_semaphore = (SemaphoreInfo *) NULL, @@ -197,8 +197,101 @@ static LogInfo *GetLogInfo(const char *,ExceptionInfo *); static MagickBooleanType - IsLogListInstantiated(ExceptionInfo *), - LoadLogLists(const char *,ExceptionInfo *); + IsLogCacheInstantiated(ExceptionInfo *), + LoadLogCache(const char *,const char *,const size_t,ExceptionInfo *); + +/* +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% % +% % +% % +% A c q u i r e L o g C a c h e % +% % +% % +% % +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% AcquireLogCache() caches one or more log configurations which provides a +% mapping between log attributes and log name. +% +% The format of the AcquireLogCache method is: +% +% LinkedListInfo *AcquireLogCache(const char *filename, +% ExceptionInfo *exception) +% +% A description of each parameter follows: +% +% o filename: the log configuration filename. +% +% o exception: return any errors or warnings in this structure. +% +*/ +static LinkedListInfo *AcquireLogCache(const char *filename, + ExceptionInfo *exception) +{ + const StringInfo + *option; + + LinkedListInfo + *log_cache, + *options; + + MagickStatusType + status; + + register ssize_t + i; + + /* + Load external log map. + */ + log_cache=NewLinkedList(0); + if (log_cache == (LinkedListInfo *) NULL) + ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); + status=MagickTrue; + options=GetConfigureOptions(filename,exception); + option=(const StringInfo *) GetNextValueInLinkedList(options); + while (option != (const StringInfo *) NULL) + { + status&=LoadLogCache((const char *) GetStringInfoDatum(option), + GetStringInfoPath(option),0,exception); + option=(const StringInfo *) GetNextValueInLinkedList(options); + } + options=DestroyConfigureOptions(options); + /* + Load built-in log map. + */ + for (i=0; i < (ssize_t) (sizeof(LogMap)/sizeof(*LogMap)); i++) + { + LogInfo + *log_info; + + register const LogMapInfo + *p; + + p=LogMap+i; + log_info=(LogInfo *) AcquireMagickMemory(sizeof(*log_info)); + if (log_info == (LogInfo *) NULL) + { + (void) ThrowMagickException(exception,GetMagickModule(), + ResourceLimitError,"MemoryAllocationFailed","`%s'",p->filename); + continue; + } + (void) ResetMagickMemory(log_info,0,sizeof(*log_info)); + log_info->path=ConstantString("[built-in]"); + GetTimerInfo((TimerInfo *) &log_info->timer); + log_info->event_mask=p->event_mask; + log_info->handler_mask=p->handler_mask; + log_info->filename=ConstantString(p->filename); + log_info->format=ConstantString(p->format); + log_info->signature=MagickSignature; + status&=AppendValueToLinkedList(log_cache,log_info); + if (status == MagickFalse) + (void) ThrowMagickException(exception,GetMagickModule(), + ResourceLimitError,"MemoryAllocationFailed","`%s'",log_info->name); + } + return(log_cache); +} /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -272,14 +365,14 @@ static LogInfo *GetLogInfo(const char *name,ExceptionInfo *exception) *p; assert(exception != (ExceptionInfo *) NULL); - if (IsLogListInstantiated(exception) == MagickFalse) + if (IsLogCacheInstantiated(exception) == MagickFalse) return((LogInfo *) NULL); /* Search for log tag. */ LockSemaphoreInfo(log_semaphore); - ResetLinkedListIterator(log_list); - p=(LogInfo *) GetNextValueInLinkedList(log_list); + ResetLinkedListIterator(log_cache); + p=(LogInfo *) GetNextValueInLinkedList(log_cache); if ((name == (const char *) NULL) || (LocaleCompare(name,"*") == 0)) { UnlockSemaphoreInfo(log_semaphore); @@ -289,11 +382,11 @@ static LogInfo *GetLogInfo(const char *name,ExceptionInfo *exception) { if (LocaleCompare(name,p->name) == 0) break; - p=(LogInfo *) GetNextValueInLinkedList(log_list); + p=(LogInfo *) GetNextValueInLinkedList(log_cache); } if (p != (LogInfo *) NULL) - (void) InsertValueInLinkedList(log_list,0, - RemoveElementByValueFromLinkedList(log_list,p)); + (void) InsertValueInLinkedList(log_cache,0, + RemoveElementByValueFromLinkedList(log_cache,p)); UnlockSemaphoreInfo(log_semaphore); return(p); } @@ -369,21 +462,21 @@ MagickExport const LogInfo **GetLogInfoList(const char *pattern, if (p == (const LogInfo *) NULL) return((const LogInfo **) NULL); preferences=(const LogInfo **) AcquireQuantumMemory((size_t) - GetNumberOfElementsInLinkedList(log_list)+1UL,sizeof(*preferences)); + GetNumberOfElementsInLinkedList(log_cache)+1UL,sizeof(*preferences)); if (preferences == (const LogInfo **) NULL) return((const LogInfo **) NULL); /* Generate log list. */ LockSemaphoreInfo(log_semaphore); - ResetLinkedListIterator(log_list); - p=(const LogInfo *) GetNextValueInLinkedList(log_list); + ResetLinkedListIterator(log_cache); + p=(const LogInfo *) GetNextValueInLinkedList(log_cache); for (i=0; p != (const LogInfo *) NULL; ) { if ((p->stealth == MagickFalse) && (GlobExpression(p->name,pattern,MagickFalse) != MagickFalse)) preferences[i++]=p; - p=(const LogInfo *) GetNextValueInLinkedList(log_list); + p=(const LogInfo *) GetNextValueInLinkedList(log_cache); } UnlockSemaphoreInfo(log_semaphore); qsort((void *) preferences,(size_t) i,sizeof(*preferences),LogInfoCompare); @@ -462,21 +555,21 @@ MagickExport char **GetLogList(const char *pattern, if (p == (const LogInfo *) NULL) return((char **) NULL); preferences=(char **) AcquireQuantumMemory((size_t) - GetNumberOfElementsInLinkedList(log_list)+1UL,sizeof(*preferences)); + GetNumberOfElementsInLinkedList(log_cache)+1UL,sizeof(*preferences)); if (preferences == (char **) NULL) return((char **) NULL); /* Generate log list. */ LockSemaphoreInfo(log_semaphore); - ResetLinkedListIterator(log_list); - p=(const LogInfo *) GetNextValueInLinkedList(log_list); + ResetLinkedListIterator(log_cache); + p=(const LogInfo *) GetNextValueInLinkedList(log_cache); for (i=0; p != (const LogInfo *) NULL; ) { if ((p->stealth == MagickFalse) && (GlobExpression(p->name,pattern,MagickFalse) != MagickFalse)) preferences[i++]=ConstantString(p->name); - p=(const LogInfo *) GetNextValueInLinkedList(log_list); + p=(const LogInfo *) GetNextValueInLinkedList(log_cache); } UnlockSemaphoreInfo(log_semaphore); qsort((void *) preferences,(size_t) i,sizeof(*preferences),LogCompare); @@ -513,33 +606,36 @@ MagickExport const char *GetLogName(void) % % % % % % -+ I s L o g L i s t I n s t a n t i a t e d % ++ I s L o g C a c h e I n s t a n t i a t e d % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % -% IsLogListInstantiated() determines if the log list is instantiated. If not, +% IsLogCacheInstantiated() determines if the log list is instantiated. If not, % it instantiates the list and returns it. % % The format of the IsLogInstantiated method is: % -% MagickBooleanType IsLogListInstantiated(ExceptionInfo *exception) +% MagickBooleanType IsLogCacheInstantiated(ExceptionInfo *exception) % % A description of each parameter follows. % % o exception: return any errors or warnings in this structure. % */ -static MagickBooleanType IsLogListInstantiated(ExceptionInfo *exception) +static MagickBooleanType IsLogCacheInstantiated(ExceptionInfo *exception) { - if (log_semaphore == (SemaphoreInfo *) NULL) - ActivateSemaphoreInfo(&log_semaphore); - LockSemaphoreInfo(log_semaphore); - if (log_list == (LinkedListInfo *) NULL) - (void) LoadLogLists(LogFilename,exception); - UnlockSemaphoreInfo(log_semaphore); - return(log_list != (LinkedListInfo *) NULL ? MagickTrue : MagickFalse); + if (log_cache == (LinkedListInfo *) NULL) + { + if (log_semaphore == (SemaphoreInfo *) NULL) + ActivateSemaphoreInfo(&log_semaphore); + LockSemaphoreInfo(log_semaphore); + if (log_cache == (LinkedListInfo *) NULL) + log_cache=AcquireLogCache(LogFilename,exception); + UnlockSemaphoreInfo(log_semaphore); + } + return(log_cache != (LinkedListInfo *) NULL ? MagickTrue : MagickFalse); } /* @@ -569,8 +665,8 @@ MagickExport MagickBooleanType IsEventLogging(void) ExceptionInfo *exception; - if ((log_list == (LinkedListInfo *) NULL) || - (IsLinkedListEmpty(log_list) != MagickFalse)) + if ((log_cache == (LinkedListInfo *) NULL) || + (IsLinkedListEmpty(log_cache) != MagickFalse)) return(MagickFalse); exception=AcquireExceptionInfo(); log_info=GetLogInfo("*",exception); @@ -759,8 +855,8 @@ MagickPrivate void LogComponentTerminus(void) if (log_semaphore == (SemaphoreInfo *) NULL) ActivateSemaphoreInfo(&log_semaphore); LockSemaphoreInfo(log_semaphore); - if (log_list != (LinkedListInfo *) NULL) - log_list=DestroyLinkedList(log_list,DestroyLogElement); + if (log_cache != (LinkedListInfo *) NULL) + log_cache=DestroyLinkedList(log_cache,DestroyLogElement); UnlockSemaphoreInfo(log_semaphore); RelinquishSemaphoreInfo(&log_semaphore); } @@ -1278,12 +1374,12 @@ MagickBooleanType LogMagickEvent(const LogEventType type,const char *module, % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % -% LoadLogList() loads the log configuration file which provides a +% LoadLogCache() loads the log configurations which provides a % mapping between log attributes and log name. % -% The format of the LoadLogList method is: +% The format of the LoadLogCache method is: % -% MagickBooleanType LoadLogList(const char *xml,const char *filename, +% MagickBooleanType LoadLogCache(const char *xml,const char *filename, % const size_t depth,ExceptionInfo *exception) % % A description of each parameter follows: @@ -1297,7 +1393,7 @@ MagickBooleanType LogMagickEvent(const LogEventType type,const char *module, % o exception: return any errors or warnings in this structure. % */ -static MagickBooleanType LoadLogList(const char *xml,const char *filename, +static MagickBooleanType LoadLogCache(const char *xml,const char *filename, const size_t depth,ExceptionInfo *exception) { char @@ -1318,10 +1414,10 @@ static MagickBooleanType LoadLogList(const char *xml,const char *filename, */ if (xml == (const char *) NULL) return(MagickFalse); - if (log_list == (LinkedListInfo *) NULL) + if (log_cache == (LinkedListInfo *) NULL) { - log_list=NewLinkedList(0); - if (log_list == (LinkedListInfo *) NULL) + log_cache=NewLinkedList(0); + if (log_cache == (LinkedListInfo *) NULL) { ThrowFileException(exception,ResourceLimitError, "MemoryAllocationFailed",filename); @@ -1391,7 +1487,7 @@ static MagickBooleanType LoadLogList(const char *xml,const char *filename, xml=FileToString(path,~0UL,exception); if (xml != (char *) NULL) { - status&=LoadLogList(xml,path,depth+1,exception); + status&=LoadLogCache(xml,path,depth+1,exception); xml=DestroyString(xml); } } @@ -1417,7 +1513,7 @@ static MagickBooleanType LoadLogList(const char *xml,const char *filename, continue; if (LocaleCompare(keyword,"") == 0) { - status=AppendValueToLinkedList(log_list,log_info); + status=AppendValueToLinkedList(log_cache,log_info); if (status == MagickFalse) (void) ThrowMagickException(exception,GetMagickModule(), ResourceLimitError,"MemoryAllocationFailed","`%s'",filename); @@ -1509,7 +1605,7 @@ static MagickBooleanType LoadLogList(const char *xml,const char *filename, } } token=DestroyString(token); - if (log_list == (LinkedListInfo *) NULL) + if (log_cache == (LinkedListInfo *) NULL) return(MagickFalse); return(status != 0 ? MagickTrue : MagickFalse); } @@ -1519,105 +1615,6 @@ static MagickBooleanType LoadLogList(const char *xml,const char *filename, % % % % % % -% L o a d L o g L i s t s % -% % -% % -% % -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% -% LoadLogLists() loads one or more log configuration file which provides a -% mapping between log attributes and log name. -% -% The format of the LoadLogLists method is: -% -% MagickBooleanType LoadLogLists(const char *filename, -% ExceptionInfo *exception) -% -% A description of each parameter follows: -% -% o filename: the log configuration filename. -% -% o exception: return any errors or warnings in this structure. -% -*/ -static MagickBooleanType LoadLogLists(const char *filename, - ExceptionInfo *exception) -{ - const StringInfo - *option; - - LinkedListInfo - *options; - - MagickStatusType - status; - - register ssize_t - i; - - /* - Load external log map. - */ - if (log_list == (LinkedListInfo *) NULL) - { - log_list=NewLinkedList(0); - if (log_list == (LinkedListInfo *) NULL) - { - ThrowFileException(exception,ResourceLimitError, - "MemoryAllocationFailed",filename); - return(MagickFalse); - } - } - status=MagickTrue; - options=GetConfigureOptions(filename,exception); - option=(const StringInfo *) GetNextValueInLinkedList(options); - while (option != (const StringInfo *) NULL) - { - status&=LoadLogList((const char *) GetStringInfoDatum(option), - GetStringInfoPath(option),0,exception); - option=(const StringInfo *) GetNextValueInLinkedList(options); - } - options=DestroyConfigureOptions(options); - /* - Load built-in log map. - */ - for (i=0; i < (ssize_t) (sizeof(LogMap)/sizeof(*LogMap)); i++) - { - LogInfo - *log_info; - - register const LogMapInfo - *p; - - p=LogMap+i; - log_info=(LogInfo *) AcquireMagickMemory(sizeof(*log_info)); - if (log_info == (LogInfo *) NULL) - { - (void) ThrowMagickException(exception,GetMagickModule(), - ResourceLimitError,"MemoryAllocationFailed","`%s'",p->filename); - continue; - } - (void) ResetMagickMemory(log_info,0,sizeof(*log_info)); - log_info->path=ConstantString("[built-in]"); - GetTimerInfo((TimerInfo *) &log_info->timer); - log_info->event_mask=p->event_mask; - log_info->handler_mask=p->handler_mask; - log_info->filename=ConstantString(p->filename); - log_info->format=ConstantString(p->format); - log_info->signature=MagickSignature; - status&=AppendValueToLinkedList(log_list,log_info); - if (status == MagickFalse) - (void) ThrowMagickException(exception,GetMagickModule(), - ResourceLimitError,"MemoryAllocationFailed","`%s'",log_info->name); - } - return(status != 0 ? MagickTrue : MagickFalse); -} - -/* -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% % -% % -% % + P a r s e L o g H a n d l e r s % % % % % @@ -1711,7 +1708,7 @@ MagickExport LogEventType SetLogEventMask(const char *events) exception=DestroyExceptionInfo(exception); option=ParseCommandOption(MagickLogEventOptions,MagickTrue,events); LockSemaphoreInfo(log_semaphore); - log_info=(LogInfo *) GetValueFromLinkedList(log_list,0); + log_info=(LogInfo *) GetValueFromLinkedList(log_cache,0); log_info->event_mask=(LogEventType) option; if (option == -1) log_info->event_mask=UndefinedEvents; @@ -1794,7 +1791,7 @@ MagickExport void SetLogMethod(MagickLogMethod method) log_info=(LogInfo *) GetLogInfo("*",exception); exception=DestroyExceptionInfo(exception); LockSemaphoreInfo(log_semaphore); - log_info=(LogInfo *) GetValueFromLinkedList(log_list,0); + log_info=(LogInfo *) GetValueFromLinkedList(log_cache,0); log_info->handler_mask=(LogHandlerType) (log_info->handler_mask | MethodHandler); log_info->method=method; diff --git a/MagickCore/magic.c b/MagickCore/magic.c index c70552ffb..abab71d28 100644 --- a/MagickCore/magic.c +++ b/MagickCore/magic.c @@ -204,7 +204,7 @@ static const MagicMapInfo }; static LinkedListInfo - *magic_list = (LinkedListInfo *) NULL; + *magic_cache = (LinkedListInfo *) NULL; static SemaphoreInfo *magic_semaphore = (SemaphoreInfo *) NULL; @@ -213,8 +213,107 @@ static SemaphoreInfo Forward declarations. */ static MagickBooleanType - IsMagicListInstantiated(ExceptionInfo *), - LoadMagicLists(const char *,ExceptionInfo *); + IsMagicCacheInstantiated(ExceptionInfo *), + LoadMagicCache(const char *,const char *,const size_t,ExceptionInfo *); + +/* +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% % +% % +% % +% A c q u i r e M a g i c L i s t s % +% % +% % +% % +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% AcquireMagicCache() caches one or more magic configurations which provides a +% mapping between magic attributes and a magic name. +% +% The format of the AcquireMagicCache method is: +% +% LinkedListInfo *AcquireMagicCache(const char *filename, +% ExceptionInfo *exception) +% +% A description of each parameter follows: +% +% o filename: the font file name. +% +% o exception: return any errors or warnings in this structure. +% +*/ +static LinkedListInfo *AcquireMagicCache(const char *filename, + ExceptionInfo *exception) +{ + char + path[MaxTextExtent]; + + const StringInfo + *option; + + LinkedListInfo + *magic_cache, + *options; + + MagickStatusType + status; + + register ssize_t + i; + + /* + Load external magic map. + */ + magic_cache=NewLinkedList(0); + if (magic_cache == (LinkedListInfo *) NULL) + ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); + status=MagickTrue; + *path='\0'; + options=GetConfigureOptions(filename,exception); + option=(const StringInfo *) GetNextValueInLinkedList(options); + while (option != (const StringInfo *) NULL) + { + (void) CopyMagickString(path,GetStringInfoPath(option),MaxTextExtent); + status&=LoadMagicCache((const char *) GetStringInfoDatum(option), + GetStringInfoPath(option),0,exception); + option=(const StringInfo *) GetNextValueInLinkedList(options); + } + options=DestroyConfigureOptions(options); + /* + Load built-in magic map. + */ + for (i=0; i < (ssize_t) (sizeof(MagicMap)/sizeof(*MagicMap)); i++) + { + MagicInfo + *magic_info; + + register const MagicMapInfo + *p; + + p=MagicMap+i; + magic_info=(MagicInfo *) AcquireMagickMemory(sizeof(*magic_info)); + if (magic_info == (MagicInfo *) NULL) + { + (void) ThrowMagickException(exception,GetMagickModule(), + ResourceLimitError,"MemoryAllocationFailed","`%s'",p->name); + continue; + } + (void) ResetMagickMemory(magic_info,0,sizeof(*magic_info)); + magic_info->path=(char *) "[built-in]"; + magic_info->name=(char *) p->name; + magic_info->offset=p->offset; + magic_info->target=(char *) p->magic; + magic_info->magic=(unsigned char *) p->magic; + magic_info->length=p->length; + magic_info->exempt=MagickTrue; + magic_info->signature=MagickSignature; + status&=AppendValueToLinkedList(magic_cache,magic_info); + if (status == MagickFalse) + (void) ThrowMagickException(exception,GetMagickModule(), + ResourceLimitError,"MemoryAllocationFailed","`%s'",magic_info->name); + } + return(magic_cache); +} /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -252,16 +351,14 @@ MagickExport const MagicInfo *GetMagicInfo(const unsigned char *magic, *p; assert(exception != (ExceptionInfo *) NULL); - if (IsMagicListInstantiated(exception) == MagickFalse) - return((const MagicInfo *) NULL); - if (length == 0) + if (IsMagicCacheInstantiated(exception) == MagickFalse) return((const MagicInfo *) NULL); /* Search for magic tag. */ LockSemaphoreInfo(magic_semaphore); - ResetLinkedListIterator(magic_list); - p=(const MagicInfo *) GetNextValueInLinkedList(magic_list); + ResetLinkedListIterator(magic_cache); + p=(const MagicInfo *) GetNextValueInLinkedList(magic_cache); if (magic == (const unsigned char *) NULL) { UnlockSemaphoreInfo(magic_semaphore); @@ -273,11 +370,11 @@ MagickExport const MagicInfo *GetMagicInfo(const unsigned char *magic, if (((size_t) (p->offset+p->length) <= length) && (memcmp(magic+p->offset,p->magic,p->length) == 0)) break; - p=(const MagicInfo *) GetNextValueInLinkedList(magic_list); + p=(const MagicInfo *) GetNextValueInLinkedList(magic_cache); } if (p != (const MagicInfo *) NULL) - (void) InsertValueInLinkedList(magic_list,0, - RemoveElementByValueFromLinkedList(magic_list,p)); + (void) InsertValueInLinkedList(magic_cache,0, + RemoveElementByValueFromLinkedList(magic_cache,p)); UnlockSemaphoreInfo(magic_semaphore); return(p); } @@ -355,21 +452,21 @@ MagickExport const MagicInfo **GetMagicInfoList(const char *pattern, if (p == (const MagicInfo *) NULL) return((const MagicInfo **) NULL); aliases=(const MagicInfo **) AcquireQuantumMemory((size_t) - GetNumberOfElementsInLinkedList(magic_list)+1UL,sizeof(*aliases)); + GetNumberOfElementsInLinkedList(magic_cache)+1UL,sizeof(*aliases)); if (aliases == (const MagicInfo **) NULL) return((const MagicInfo **) NULL); /* Generate magic list. */ LockSemaphoreInfo(magic_semaphore); - ResetLinkedListIterator(magic_list); - p=(const MagicInfo *) GetNextValueInLinkedList(magic_list); + ResetLinkedListIterator(magic_cache); + p=(const MagicInfo *) GetNextValueInLinkedList(magic_cache); for (i=0; p != (const MagicInfo *) NULL; ) { if ((p->stealth == MagickFalse) && (GlobExpression(p->name,pattern,MagickFalse) != MagickFalse)) aliases[i++]=p; - p=(const MagicInfo *) GetNextValueInLinkedList(magic_list); + p=(const MagicInfo *) GetNextValueInLinkedList(magic_cache); } UnlockSemaphoreInfo(magic_semaphore); qsort((void *) aliases,(size_t) i,sizeof(*aliases),MagicInfoCompare); @@ -450,18 +547,18 @@ MagickExport char **GetMagicList(const char *pattern,size_t *number_aliases, if (p == (const MagicInfo *) NULL) return((char **) NULL); aliases=(char **) AcquireQuantumMemory((size_t) - GetNumberOfElementsInLinkedList(magic_list)+1UL,sizeof(*aliases)); + GetNumberOfElementsInLinkedList(magic_cache)+1UL,sizeof(*aliases)); if (aliases == (char **) NULL) return((char **) NULL); LockSemaphoreInfo(magic_semaphore); - ResetLinkedListIterator(magic_list); - p=(const MagicInfo *) GetNextValueInLinkedList(magic_list); + ResetLinkedListIterator(magic_cache); + p=(const MagicInfo *) GetNextValueInLinkedList(magic_cache); for (i=0; p != (const MagicInfo *) NULL; ) { if ((p->stealth == MagickFalse) && (GlobExpression(p->name,pattern,MagickFalse) != MagickFalse)) aliases[i++]=ConstantString(p->name); - p=(const MagicInfo *) GetNextValueInLinkedList(magic_list); + p=(const MagicInfo *) GetNextValueInLinkedList(magic_cache); } UnlockSemaphoreInfo(magic_semaphore); qsort((void *) aliases,(size_t) i,sizeof(*aliases),MagicCompare); @@ -505,33 +602,36 @@ MagickExport const char *GetMagicName(const MagicInfo *magic_info) % % % % % % -+ I s M a g i c L i s t I n s t a n t i a t e d % ++ I s M a g i c C a c h e I n s t a n t i a t e d % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % -% IsMagicListInstantiated() determines if the magic list is instantiated. +% IsMagicCacheInstantiated() determines if the magic list is instantiated. % If not, it instantiates the list and returns it. % % The format of the IsMagicInstantiated method is: % -% MagickBooleanType IsMagicListInstantiated(ExceptionInfo *exception) +% MagickBooleanType IsMagicCacheInstantiated(ExceptionInfo *exception) % % A description of each parameter follows. % % o exception: return any errors or warnings in this structure. % */ -static MagickBooleanType IsMagicListInstantiated(ExceptionInfo *exception) +static MagickBooleanType IsMagicCacheInstantiated(ExceptionInfo *exception) { - if (magic_semaphore == (SemaphoreInfo *) NULL) - ActivateSemaphoreInfo(&magic_semaphore); - LockSemaphoreInfo(magic_semaphore); - if (magic_list == (LinkedListInfo *) NULL) - (void) LoadMagicLists(MagicFilename,exception); - UnlockSemaphoreInfo(magic_semaphore); - return(magic_list != (LinkedListInfo *) NULL ? MagickTrue : MagickFalse); + if (magic_cache == (LinkedListInfo *) NULL) + { + if (magic_semaphore == (SemaphoreInfo *) NULL) + ActivateSemaphoreInfo(&magic_semaphore); + LockSemaphoreInfo(magic_semaphore); + if (magic_cache == (LinkedListInfo *) NULL) + magic_cache=AcquireMagicCache(MagicFilename,exception); + UnlockSemaphoreInfo(magic_semaphore); + } + return(magic_cache != (LinkedListInfo *) NULL ? MagickTrue : MagickFalse); } /* @@ -632,12 +732,12 @@ MagickExport MagickBooleanType ListMagicInfo(FILE *file, % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % -% LoadMagicList() loads the magic configuration file which provides a mapping +% LoadMagicCache() loads the magic configurations which provides a mapping % between magic attributes and a magic name. % -% The format of the LoadMagicList method is: +% The format of the LoadMagicCache method is: % -% MagickBooleanType LoadMagicList(const char *xml,const char *filename, +% MagickBooleanType LoadMagicCache(const char *xml,const char *filename, % const size_t depth,ExceptionInfo *exception) % % A description of each parameter follows: @@ -651,7 +751,7 @@ MagickExport MagickBooleanType ListMagicInfo(FILE *file, % o exception: return any errors or warnings in this structure. % */ -static MagickBooleanType LoadMagicList(const char *xml,const char *filename, +static MagickBooleanType LoadMagicCache(const char *xml,const char *filename, const size_t depth,ExceptionInfo *exception) { char @@ -674,10 +774,10 @@ static MagickBooleanType LoadMagicList(const char *xml,const char *filename, "Loading magic configure file \"%s\" ...",filename); if (xml == (char *) NULL) return(MagickFalse); - if (magic_list == (LinkedListInfo *) NULL) + if (magic_cache == (LinkedListInfo *) NULL) { - magic_list=NewLinkedList(0); - if (magic_list == (LinkedListInfo *) NULL) + magic_cache=NewLinkedList(0); + if (magic_cache == (LinkedListInfo *) NULL) { ThrowFileException(exception,ResourceLimitError, "MemoryAllocationFailed",filename); @@ -748,7 +848,7 @@ static MagickBooleanType LoadMagicList(const char *xml,const char *filename, xml=FileToString(path,~0UL,exception); if (xml != (char *) NULL) { - status=LoadMagicList(xml,path,depth+1,exception); + status=LoadMagicCache(xml,path,depth+1,exception); xml=(char *) RelinquishMagickMemory(xml); } } @@ -774,7 +874,7 @@ static MagickBooleanType LoadMagicList(const char *xml,const char *filename, continue; if (LocaleCompare(keyword,"/>") == 0) { - status=AppendValueToLinkedList(magic_list,magic_info); + status=AppendValueToLinkedList(magic_cache,magic_info); if (status == MagickFalse) (void) ThrowMagickException(exception,GetMagickModule(), ResourceLimitError,"MemoryAllocationFailed","`%s'", @@ -892,111 +992,6 @@ static MagickBooleanType LoadMagicList(const char *xml,const char *filename, % % % % % % -% L o a d M a g i c L i s t s % -% % -% % -% % -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% -% LoadMagicLists() loads one or more magic configuration file which provides a -% mapping between magic attributes and a magic name. -% -% The format of the LoadMagicLists method is: -% -% MagickBooleanType LoadMagicLists(const char *filename, -% ExceptionInfo *exception) -% -% A description of each parameter follows: -% -% o filename: the font file name. -% -% o exception: return any errors or warnings in this structure. -% -*/ -static MagickBooleanType LoadMagicLists(const char *filename, - ExceptionInfo *exception) -{ - char - path[MaxTextExtent]; - - const StringInfo - *option; - - LinkedListInfo - *options; - - MagickStatusType - status; - - register ssize_t - i; - - /* - Load external magic map. - */ - if (magic_list == (LinkedListInfo *) NULL) - { - magic_list=NewLinkedList(0); - if (magic_list == (LinkedListInfo *) NULL) - { - ThrowFileException(exception,ResourceLimitError, - "MemoryAllocationFailed",filename); - return(MagickFalse); - } - } - status=MagickTrue; - *path='\0'; - options=GetConfigureOptions(filename,exception); - option=(const StringInfo *) GetNextValueInLinkedList(options); - while (option != (const StringInfo *) NULL) - { - (void) CopyMagickString(path,GetStringInfoPath(option),MaxTextExtent); - status&=LoadMagicList((const char *) GetStringInfoDatum(option), - GetStringInfoPath(option),0,exception); - option=(const StringInfo *) GetNextValueInLinkedList(options); - } - options=DestroyConfigureOptions(options); - /* - Load built-in magic map. - */ - for (i=0; i < (ssize_t) (sizeof(MagicMap)/sizeof(*MagicMap)); i++) - { - MagicInfo - *magic_info; - - register const MagicMapInfo - *p; - - p=MagicMap+i; - magic_info=(MagicInfo *) AcquireMagickMemory(sizeof(*magic_info)); - if (magic_info == (MagicInfo *) NULL) - { - (void) ThrowMagickException(exception,GetMagickModule(), - ResourceLimitError,"MemoryAllocationFailed","`%s'",p->name); - continue; - } - (void) ResetMagickMemory(magic_info,0,sizeof(*magic_info)); - magic_info->path=(char *) "[built-in]"; - magic_info->name=(char *) p->name; - magic_info->offset=p->offset; - magic_info->target=(char *) p->magic; - magic_info->magic=(unsigned char *) p->magic; - magic_info->length=p->length; - magic_info->exempt=MagickTrue; - magic_info->signature=MagickSignature; - status&=AppendValueToLinkedList(magic_list,magic_info); - if (status == MagickFalse) - (void) ThrowMagickException(exception,GetMagickModule(), - ResourceLimitError,"MemoryAllocationFailed","`%s'",magic_info->name); - } - return(status != 0 ? MagickTrue : MagickFalse); -} - -/* -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% % -% % -% % + M a g i c C o m p o n e n t G e n e s i s % % % % % @@ -1061,8 +1056,8 @@ MagickPrivate void MagicComponentTerminus(void) if (magic_semaphore == (SemaphoreInfo *) NULL) ActivateSemaphoreInfo(&magic_semaphore); LockSemaphoreInfo(magic_semaphore); - if (magic_list != (LinkedListInfo *) NULL) - magic_list=DestroyLinkedList(magic_list,DestroyMagicElement); + if (magic_cache != (LinkedListInfo *) NULL) + magic_cache=DestroyLinkedList(magic_cache,DestroyMagicElement); UnlockSemaphoreInfo(magic_semaphore); RelinquishSemaphoreInfo(&magic_semaphore); } diff --git a/MagickCore/magick.c b/MagickCore/magick.c index da6528fc8..fa823f1ef 100644 --- a/MagickCore/magick.c +++ b/MagickCore/magick.c @@ -414,6 +414,10 @@ MagickExport const MagickInfo *GetMagickInfo(const char *name, assert(exception != (ExceptionInfo *) NULL); if (IsMagickTreeInstantiated(exception) == MagickFalse) return((const MagickInfo *) NULL); +#if defined(MAGICKCORE_MODULES_SUPPORT) + if ((name != (const char *) NULL) && (LocaleCompare(name,"*") == 0)) + (void) OpenModules(exception); +#endif /* Find name in list. */ @@ -422,10 +426,6 @@ MagickExport const MagickInfo *GetMagickInfo(const char *name, p=(const MagickInfo *) GetNextValueInSplayTree(magick_list); if ((name == (const char *) NULL) || (LocaleCompare(name,"*") == 0)) { -#if defined(MAGICKCORE_MODULES_SUPPORT) - if (LocaleCompare(name,"*") == 0) - (void) OpenModules(exception); -#endif ResetSplayTreeIterator(magick_list); p=(const MagickInfo *) GetNextValueInSplayTree(magick_list); UnlockSemaphoreInfo(magick_semaphore); @@ -837,39 +837,45 @@ static void *DestroyMagickNode(void *magick_info) static MagickBooleanType IsMagickTreeInstantiated(ExceptionInfo *exception) { (void) exception; - if (magick_semaphore == (SemaphoreInfo *) NULL) - ActivateSemaphoreInfo(&magick_semaphore); - LockSemaphoreInfo(magick_semaphore); if (magick_list == (SplayTreeInfo *) NULL) { - MagickBooleanType - status; + if (magick_semaphore == (SemaphoreInfo *) NULL) + ActivateSemaphoreInfo(&magick_semaphore); + LockSemaphoreInfo(magick_semaphore); + if (magick_list == (SplayTreeInfo *) NULL) + { + MagickBooleanType + status; - MagickInfo - *magick_info; + MagickInfo + *magick_info; - magick_list=NewSplayTree(CompareSplayTreeString,(void *(*)(void *)) NULL, - DestroyMagickNode); - if (magick_list == (SplayTreeInfo *) NULL) - ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); - magick_info=SetMagickInfo("ephemeral"); - magick_info->stealth=MagickTrue; - status=AddValueToSplayTree(magick_list,magick_info->name,magick_info); - if (status == MagickFalse) - ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); - magick_info=SetMagickInfo("clipmask"); - magick_info->stealth=MagickTrue; - status=AddValueToSplayTree(magick_list,magick_info->name,magick_info); - if (status == MagickFalse) - ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); + magick_list=NewSplayTree(CompareSplayTreeString,(void *(*)(void *)) + NULL, DestroyMagickNode); + if (magick_list == (SplayTreeInfo *) NULL) + ThrowFatalException(ResourceLimitFatalError, + "MemoryAllocationFailed"); + magick_info=SetMagickInfo("ephemeral"); + magick_info->stealth=MagickTrue; + status=AddValueToSplayTree(magick_list,magick_info->name,magick_info); + if (status == MagickFalse) + ThrowFatalException(ResourceLimitFatalError, + "MemoryAllocationFailed"); + magick_info=SetMagickInfo("clipmask"); + magick_info->stealth=MagickTrue; + status=AddValueToSplayTree(magick_list,magick_info->name,magick_info); + if (status == MagickFalse) + ThrowFatalException(ResourceLimitFatalError, + "MemoryAllocationFailed"); #if defined(MAGICKCORE_MODULES_SUPPORT) - (void) GetModuleInfo((char *) NULL,exception); + (void) GetModuleInfo((char *) NULL,exception); #endif #if !defined(MAGICKCORE_BUILD_MODULES) - RegisterStaticModules(); + RegisterStaticModules(); #endif + } + UnlockSemaphoreInfo(magick_semaphore); } - UnlockSemaphoreInfo(magick_semaphore); return(magick_list != (SplayTreeInfo *) NULL ? MagickTrue : MagickFalse); } diff --git a/MagickCore/mime.c b/MagickCore/mime.c index 56fef380c..c558581bd 100644 --- a/MagickCore/mime.c +++ b/MagickCore/mime.c @@ -115,7 +115,7 @@ static const char ""; static LinkedListInfo - *mime_list = (LinkedListInfo *) NULL; + *mime_cache = (LinkedListInfo *) NULL; static SemaphoreInfo *mime_semaphore = (SemaphoreInfo *) NULL; @@ -124,7 +124,72 @@ static SemaphoreInfo Forward declarations. */ static MagickBooleanType - IsMimeListInstantiated(ExceptionInfo *); + IsMimeCacheInstantiated(ExceptionInfo *), + LoadMimeCache(const char *,const char *,const size_t,ExceptionInfo *); + +/* +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% % +% % +% % +% A c q u i r e M i m e C a c h e % +% % +% % +% % +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% AcquireMimeCache() caches one or more magic configurations which provides a +% mapping between magic attributes and a magic name. +% +% The format of the AcquireMimeCache method is: +% +% LinkedListInfo *AcquireMimeCache(const char *filename, +% ExceptionInfo *exception) +% +% A description of each parameter follows: +% +% o filename: the font file name. +% +% o exception: return any errors or warnings in this structure. +% +*/ +MagickExport LinkedListInfo *AcquireMimeCache(const char *filename, + ExceptionInfo *exception) +{ +#if defined(MAGICKCORE_ZERO_CONFIGURATION_SUPPORT) + return(LoadMimeCache(MimeMap,"built-in",0,exception)); +#else + const StringInfo + *option; + + LinkedListInfo + *mime_cache, + *options; + + MagickStatusType + status; + + mime_cache=NewLinkedList(0); + if (mime_cache == (LinkedListInfo *) NULL) + ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); + status=MagickTrue; + options=GetConfigureOptions(filename,exception); + option=(const StringInfo *) GetNextValueInLinkedList(options); + while (option != (const StringInfo *) NULL) + { + status&=LoadMimeCache((const char *) GetStringInfoDatum(option), + GetStringInfoPath(option),0,exception); + option=(const StringInfo *) GetNextValueInLinkedList(options); + } + options=DestroyConfigureOptions(options); + if ((mime_cache == (LinkedListInfo *) NULL) || + (IsLinkedListEmpty(mime_cache) != MagickFalse)) + status&=LoadMimeCache(MimeMap,"built-in",0,exception); + else + ClearMagickException(exception); + return(mime_cache); +#endif +} /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -184,11 +249,7 @@ MagickExport const MimeInfo *GetMimeInfo(const char *filename, value; assert(exception != (ExceptionInfo *) NULL); - if (IsMimeListInstantiated(exception) == MagickFalse) - return((const MimeInfo *) NULL); - if ((magic == (const unsigned char *) NULL) || (length == 0)) - return((const MimeInfo *) GetValueFromLinkedList(mime_list,0)); - if (length == 0) + if (IsMimeCacheInstantiated(exception) == MagickFalse) return((const MimeInfo *) NULL); /* Search for mime tag. @@ -196,22 +257,27 @@ MagickExport const MimeInfo *GetMimeInfo(const char *filename, mime_info=(const MimeInfo *) NULL; lsb_first=1; LockSemaphoreInfo(mime_semaphore); - ResetLinkedListIterator(mime_list); - p=(const MimeInfo *) GetNextValueInLinkedList(mime_list); + ResetLinkedListIterator(mime_cache); + p=(const MimeInfo *) GetNextValueInLinkedList(mime_cache); + if ((magic == (const unsigned char *) NULL) || (length == 0)) + { + UnlockSemaphoreInfo(mime_semaphore); + return(p); + } while (p != (const MimeInfo *) NULL) { assert(p->offset >= 0); if (mime_info != (const MimeInfo *) NULL) if (p->priority > mime_info->priority) { - p=(const MimeInfo *) GetNextValueInLinkedList(mime_list); + p=(const MimeInfo *) GetNextValueInLinkedList(mime_cache); continue; } if ((p->pattern != (char *) NULL) && (filename != (char *) NULL)) { if (GlobExpression(filename,p->pattern,MagickFalse) != MagickFalse) mime_info=p; - p=(const MimeInfo *) GetNextValueInLinkedList(mime_list); + p=(const MimeInfo *) GetNextValueInLinkedList(mime_cache); continue; } switch (p->data_type) @@ -314,11 +380,11 @@ MagickExport const MimeInfo *GetMimeInfo(const char *filename, break; } } - p=(const MimeInfo *) GetNextValueInLinkedList(mime_list); + p=(const MimeInfo *) GetNextValueInLinkedList(mime_cache); } if (p != (const MimeInfo *) NULL) - (void) InsertValueInLinkedList(mime_list,0, - RemoveElementByValueFromLinkedList(mime_list,p)); + (void) InsertValueInLinkedList(mime_cache,0, + RemoveElementByValueFromLinkedList(mime_cache,p)); UnlockSemaphoreInfo(mime_semaphore); return(p); } @@ -397,21 +463,21 @@ MagickExport const MimeInfo **GetMimeInfoList(const char *pattern, if (p == (const MimeInfo *) NULL) return((const MimeInfo **) NULL); aliases=(const MimeInfo **) AcquireQuantumMemory((size_t) - GetNumberOfElementsInLinkedList(mime_list)+1UL,sizeof(*aliases)); + GetNumberOfElementsInLinkedList(mime_cache)+1UL,sizeof(*aliases)); if (aliases == (const MimeInfo **) NULL) return((const MimeInfo **) NULL); /* Generate mime list. */ LockSemaphoreInfo(mime_semaphore); - ResetLinkedListIterator(mime_list); - p=(const MimeInfo *) GetNextValueInLinkedList(mime_list); + ResetLinkedListIterator(mime_cache); + p=(const MimeInfo *) GetNextValueInLinkedList(mime_cache); for (i=0; p != (const MimeInfo *) NULL; ) { if ((p->stealth == MagickFalse) && (GlobExpression(p->type,pattern,MagickFalse) != MagickFalse)) aliases[i++]=p; - p=(const MimeInfo *) GetNextValueInLinkedList(mime_list); + p=(const MimeInfo *) GetNextValueInLinkedList(mime_cache); } UnlockSemaphoreInfo(mime_semaphore); qsort((void *) aliases,(size_t) i,sizeof(*aliases),MimeInfoCompare); @@ -492,18 +558,18 @@ MagickExport char **GetMimeList(const char *pattern, if (p == (const MimeInfo *) NULL) return((char **) NULL); aliases=(char **) AcquireQuantumMemory((size_t) - GetNumberOfElementsInLinkedList(mime_list)+1UL,sizeof(*aliases)); + GetNumberOfElementsInLinkedList(mime_cache)+1UL,sizeof(*aliases)); if (aliases == (char **) NULL) return((char **) NULL); LockSemaphoreInfo(mime_semaphore); - ResetLinkedListIterator(mime_list); - p=(const MimeInfo *) GetNextValueInLinkedList(mime_list); + ResetLinkedListIterator(mime_cache); + p=(const MimeInfo *) GetNextValueInLinkedList(mime_cache); for (i=0; p != (const MimeInfo *) NULL; ) { if ((p->stealth == MagickFalse) && (GlobExpression(p->type,pattern,MagickFalse) != MagickFalse)) aliases[i++]=ConstantString(p->type); - p=(const MimeInfo *) GetNextValueInLinkedList(mime_list); + p=(const MimeInfo *) GetNextValueInLinkedList(mime_cache); } UnlockSemaphoreInfo(mime_semaphore); qsort((void *) aliases,(size_t) i,sizeof(*aliases),MimeCompare); @@ -577,33 +643,36 @@ MagickExport const char *GetMimeType(const MimeInfo *mime_info) % % % % % % -+ I s M i m e L i s t I n s t a n t i a t e d % ++ I s M i m e C a c h e I n s t a n t i a t e d % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % -% IsMimeListInstantiated() determines if the mime list is instantiated. If +% IsMimeCacheInstantiated() determines if the mime list is instantiated. If % not, it instantiates the list and returns it. % % The format of the IsMimeInstantiated method is: % -% MagickBooleanType IsMimeListInstantiated(ExceptionInfo *exception) +% MagickBooleanType IsMimeCacheInstantiated(ExceptionInfo *exception) % % A description of each parameter follows. % % o exception: return any errors or warnings in this structure. % */ -static MagickBooleanType IsMimeListInstantiated(ExceptionInfo *exception) +static MagickBooleanType IsMimeCacheInstantiated(ExceptionInfo *exception) { - if (mime_semaphore == (SemaphoreInfo *) NULL) - ActivateSemaphoreInfo(&mime_semaphore); - LockSemaphoreInfo(mime_semaphore); - if (mime_list == (LinkedListInfo *) NULL) - (void) LoadMimeLists(MimeFilename,exception); - UnlockSemaphoreInfo(mime_semaphore); - return(mime_list != (LinkedListInfo *) NULL ? MagickTrue : MagickFalse); + if (mime_cache == (LinkedListInfo *) NULL) + { + if (mime_semaphore == (SemaphoreInfo *) NULL) + ActivateSemaphoreInfo(&mime_semaphore); + LockSemaphoreInfo(mime_semaphore); + if (mime_cache == (LinkedListInfo *) NULL) + mime_cache=AcquireMimeCache(MimeFilename,exception); + UnlockSemaphoreInfo(mime_semaphore); + } + return(mime_cache != (LinkedListInfo *) NULL ? MagickTrue : MagickFalse); } /* @@ -701,12 +770,12 @@ MagickExport MagickBooleanType ListMimeInfo(FILE *file,ExceptionInfo *exception) % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % -% LoadMimeList() loads the magic configuration file which provides a mapping +% LoadMimeCache() loads the magic configurations which provides a mapping % between magic attributes and a magic name. % -% The format of the LoadMimeList method is: +% The format of the LoadMimeCache method is: % -% MagickBooleanType LoadMimeList(const char *xml,const char *filename, +% MagickBooleanType LoadMimeCache(const char *xml,const char *filename, % const size_t depth,ExceptionInfo *exception) % % A description of each parameter follows: @@ -720,7 +789,7 @@ MagickExport MagickBooleanType ListMimeInfo(FILE *file,ExceptionInfo *exception) % o exception: return any errors or warnings in this structure. % */ -static MagickBooleanType LoadMimeList(const char *xml,const char *filename, +static MagickBooleanType LoadMimeCache(const char *xml,const char *filename, const size_t depth,ExceptionInfo *exception) { const char @@ -744,10 +813,10 @@ static MagickBooleanType LoadMimeList(const char *xml,const char *filename, "Loading mime map \"%s\" ...",filename); if (xml == (const char *) NULL) return(MagickFalse); - if (mime_list == (LinkedListInfo *) NULL) + if (mime_cache == (LinkedListInfo *) NULL) { - mime_list=NewLinkedList(0); - if (mime_list == (LinkedListInfo *) NULL) + mime_cache=NewLinkedList(0); + if (mime_cache == (LinkedListInfo *) NULL) { ThrowFileException(exception,ResourceLimitError, "MemoryAllocationFailed",filename); @@ -787,7 +856,7 @@ static MagickBooleanType LoadMimeList(const char *xml,const char *filename, xml=FileToString(path,~0UL,exception); if (xml != (char *) NULL) { - status=LoadMimeList(xml,path,depth+1,exception); + status=LoadMimeCache(xml,path,depth+1,exception); xml=DestroyString(xml); } } @@ -902,7 +971,7 @@ static MagickBooleanType LoadMimeList(const char *xml,const char *filename, attribute=GetXMLTreeAttribute(mime,"type"); if (attribute != (const char *) NULL) mime_info->type=ConstantString(attribute); - status=AppendValueToLinkedList(mime_list,mime_info); + status=AppendValueToLinkedList(mime_cache,mime_info); if (status == MagickFalse) (void) ThrowMagickException(exception,GetMagickModule(), ResourceLimitError,"MemoryAllocationFailed","`%s'",filename); @@ -917,66 +986,6 @@ static MagickBooleanType LoadMimeList(const char *xml,const char *filename, % % % % % % -% L o a d M i m e L i s t s % -% % -% % -% % -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% -% LoadMimeList() loads one or more magic configuration file which provides a -% mapping between magic attributes and a magic name. -% -% The format of the LoadMimeLists method is: -% -% MagickBooleanType LoadMimeLists(const char *filename, -% ExceptionInfo *exception) -% -% A description of each parameter follows: -% -% o filename: the font file name. -% -% o exception: return any errors or warnings in this structure. -% -*/ -MagickExport MagickBooleanType LoadMimeLists(const char *filename, - ExceptionInfo *exception) -{ -#if defined(MAGICKCORE_ZERO_CONFIGURATION_SUPPORT) - return(LoadMimeList(MimeMap,"built-in",0,exception)); -#else - const StringInfo - *option; - - LinkedListInfo - *options; - - MagickStatusType - status; - - status=MagickFalse; - options=GetConfigureOptions(filename,exception); - option=(const StringInfo *) GetNextValueInLinkedList(options); - while (option != (const StringInfo *) NULL) - { - status&=LoadMimeList((const char *) GetStringInfoDatum(option), - GetStringInfoPath(option),0,exception); - option=(const StringInfo *) GetNextValueInLinkedList(options); - } - options=DestroyConfigureOptions(options); - if ((mime_list == (LinkedListInfo *) NULL) || - (IsLinkedListEmpty(mime_list) != MagickFalse)) - status&=LoadMimeList(MimeMap,"built-in",0,exception); - else - ClearMagickException(exception); - return(status != 0 ? MagickTrue : MagickFalse); -#endif -} - -/* -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% % -% % -% % + M a g i c k T o M i m e % % % % % @@ -1089,8 +1098,8 @@ MagickPrivate void MimeComponentTerminus(void) if (mime_semaphore == (SemaphoreInfo *) NULL) ActivateSemaphoreInfo(&mime_semaphore); LockSemaphoreInfo(mime_semaphore); - if (mime_list != (LinkedListInfo *) NULL) - mime_list=DestroyLinkedList(mime_list,DestroyMimeElement); + if (mime_cache != (LinkedListInfo *) NULL) + mime_cache=DestroyLinkedList(mime_cache,DestroyMimeElement); UnlockSemaphoreInfo(mime_semaphore); RelinquishSemaphoreInfo(&mime_semaphore); } diff --git a/MagickCore/module.c b/MagickCore/module.c index 4051ddd77..22d74dd2d 100644 --- a/MagickCore/module.c +++ b/MagickCore/module.c @@ -853,30 +853,36 @@ static void *DestroyModuleNode(void *module_info) static MagickBooleanType IsModuleTreeInstantiated( ExceptionInfo *magick_unused(exception)) { - if (module_semaphore == (SemaphoreInfo *) NULL) - ActivateSemaphoreInfo(&module_semaphore); - LockSemaphoreInfo(module_semaphore); if (module_list == (SplayTreeInfo *) NULL) { - MagickBooleanType - status; - - ModuleInfo - *module_info; - - module_list=NewSplayTree(CompareSplayTreeString, - (void *(*)(void *)) NULL,DestroyModuleNode); + if (module_semaphore == (SemaphoreInfo *) NULL) + ActivateSemaphoreInfo(&module_semaphore); + LockSemaphoreInfo(module_semaphore); if (module_list == (SplayTreeInfo *) NULL) - ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); - module_info=AcquireModuleInfo((const char *) NULL,"[boot-strap]"); - module_info->stealth=MagickTrue; - status=AddValueToSplayTree(module_list,module_info->tag,module_info); - if (status == MagickFalse) - ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); - if (lt_dlinit() != 0) - ThrowFatalException(ModuleFatalError,"UnableToInitializeModuleLoader"); + { + MagickBooleanType + status; + + ModuleInfo + *module_info; + + module_list=NewSplayTree(CompareSplayTreeString, + (void *(*)(void *)) NULL,DestroyModuleNode); + if (module_list == (SplayTreeInfo *) NULL) + ThrowFatalException(ResourceLimitFatalError, + "MemoryAllocationFailed"); + module_info=AcquireModuleInfo((const char *) NULL,"[boot-strap]"); + module_info->stealth=MagickTrue; + status=AddValueToSplayTree(module_list,module_info->tag,module_info); + if (status == MagickFalse) + ThrowFatalException(ResourceLimitFatalError, + "MemoryAllocationFailed"); + if (lt_dlinit() != 0) + ThrowFatalException(ModuleFatalError, + "UnableToInitializeModuleLoader"); + } + UnlockSemaphoreInfo(module_semaphore); } - UnlockSemaphoreInfo(module_semaphore); return(module_list != (SplayTreeInfo *) NULL ? MagickTrue : MagickFalse); } diff --git a/MagickCore/nt-feature.c b/MagickCore/nt-feature.c index ba9105026..c70d913fb 100644 --- a/MagickCore/nt-feature.c +++ b/MagickCore/nt-feature.c @@ -267,18 +267,18 @@ MagickExport MagickBooleanType NTIsMagickConflict(const char *magick) % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % -% NTLoadTypeLists() loads a Windows TrueType fonts. +% NTAcquireTypeCache() loads a Windows TrueType fonts. % -% The format of the NTLoadTypeLists method is: +% The format of the NTAcquireTypeCache method is: % -% MagickBooleanType NTLoadTypeLists(SplayTreeInfo *type_list) +% MagickBooleanType NTAcquireTypeCache(SplayTreeInfo *type_cache) % % A description of each parameter follows: % -% o type_list: A linked list of fonts. +% o type_cache: A linked list of fonts. % */ -MagickExport MagickBooleanType NTLoadTypeLists(SplayTreeInfo *type_list, +MagickExport MagickBooleanType NTAcquireTypeCache(SplayTreeInfo *type_cache, ExceptionInfo *exception) { HKEY @@ -538,7 +538,7 @@ MagickExport MagickBooleanType NTLoadTypeLists(SplayTreeInfo *type_list, type_info->family=ConstantString(buffer); list_entries++; - status=AddValueToSplayTree(type_list,ConstantString(type_info->name), + status=AddValueToSplayTree(type_cache,ConstantString(type_info->name), type_info); if (status == MagickFalse) (void) ThrowMagickException(exception,GetMagickModule(), diff --git a/MagickCore/policy.c b/MagickCore/policy.c index 943a81559..2db65d19f 100644 --- a/MagickCore/policy.c +++ b/MagickCore/policy.c @@ -120,7 +120,7 @@ static const PolicyMapInfo }; static LinkedListInfo - *policy_list = (LinkedListInfo *) NULL; + *policy_cache = (LinkedListInfo *) NULL; static SemaphoreInfo *policy_semaphore = (SemaphoreInfo *) NULL; @@ -129,8 +129,102 @@ static SemaphoreInfo Forward declarations. */ static MagickBooleanType - IsPolicyListInstantiated(ExceptionInfo *), - LoadPolicyLists(const char *,ExceptionInfo *); + IsPolicyCacheInstantiated(ExceptionInfo *), + LoadPolicyCache(const char *,const char *,const size_t,ExceptionInfo *); + +/* +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% % +% % +% % +% A c q u i r e P o l i c y C a c h e % +% % +% % +% % +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% AcquirePolicyCache() caches one or more policy configurations which provides +% a mapping between policy attributes and a policy name. +% +% The format of the AcquirePolicyCache method is: +% +% LinkedListInfo *AcquirePolicyCache(const char *filename, +% ExceptionInfo *exception) +% +% A description of each parameter follows: +% +% o filename: the font file name. +% +% o exception: return any errors or warnings in this structure. +% +*/ +static LinkedListInfo *AcquirePolicyCache(const char *filename, + ExceptionInfo *exception) +{ + const StringInfo + *option; + + LinkedListInfo + *options, + *policy_cache; + + MagickStatusType + status; + + register ssize_t + i; + + /* + Load external policy map. + */ + policy_cache=NewLinkedList(0); + if (policy_cache == (LinkedListInfo *) NULL) + ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); + status=MagickTrue; + options=GetConfigureOptions(filename,exception); + option=(const StringInfo *) GetNextValueInLinkedList(options); + while (option != (const StringInfo *) NULL) + { + status&=LoadPolicyCache((const char *) GetStringInfoDatum(option), + GetStringInfoPath(option),0,exception); + option=(const StringInfo *) GetNextValueInLinkedList(options); + } + options=DestroyConfigureOptions(options); + /* + Load built-in policy map. + */ + for (i=0; i < (ssize_t) (sizeof(PolicyMap)/sizeof(*PolicyMap)); i++) + { + PolicyInfo + *policy_info; + + register const PolicyMapInfo + *p; + + p=PolicyMap+i; + policy_info=(PolicyInfo *) AcquireMagickMemory(sizeof(*policy_info)); + if (policy_info == (PolicyInfo *) NULL) + { + (void) ThrowMagickException(exception,GetMagickModule(), + ResourceLimitError,"MemoryAllocationFailed","`%s'",p->name); + continue; + } + (void) ResetMagickMemory(policy_info,0,sizeof(*policy_info)); + policy_info->path=(char *) "[built-in]"; + policy_info->domain=p->domain; + policy_info->rights=p->rights; + policy_info->name=(char *) p->name; + policy_info->pattern=(char *) p->pattern; + policy_info->value=(char *) p->value; + policy_info->exempt=MagickTrue; + policy_info->signature=MagickSignature; + status&=AppendValueToLinkedList(policy_cache,policy_info); + if (status == MagickFalse) + (void) ThrowMagickException(exception,GetMagickModule(), + ResourceLimitError,"MemoryAllocationFailed","`%s'",policy_info->name); + } + return(policy_cache); +} /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -169,7 +263,7 @@ static PolicyInfo *GetPolicyInfo(const char *name,ExceptionInfo *exception) *q; assert(exception != (ExceptionInfo *) NULL); - if (IsPolicyListInstantiated(exception) == MagickFalse) + if (IsPolicyCacheInstantiated(exception) == MagickFalse) return((PolicyInfo *) NULL); /* Strip names of whitespace. @@ -188,8 +282,8 @@ static PolicyInfo *GetPolicyInfo(const char *name,ExceptionInfo *exception) Search for policy tag. */ LockSemaphoreInfo(policy_semaphore); - ResetLinkedListIterator(policy_list); - p=(PolicyInfo *) GetNextValueInLinkedList(policy_list); + ResetLinkedListIterator(policy_cache); + p=(PolicyInfo *) GetNextValueInLinkedList(policy_cache); if ((name == (const char *) NULL) || (LocaleCompare(name,"*") == 0)) { UnlockSemaphoreInfo(policy_semaphore); @@ -199,11 +293,11 @@ static PolicyInfo *GetPolicyInfo(const char *name,ExceptionInfo *exception) { if (LocaleCompare(policyname,p->name) == 0) break; - p=(PolicyInfo *) GetNextValueInLinkedList(policy_list); + p=(PolicyInfo *) GetNextValueInLinkedList(policy_cache); } if (p != (PolicyInfo *) NULL) - (void) InsertValueInLinkedList(policy_list,0, - RemoveElementByValueFromLinkedList(policy_list,p)); + (void) InsertValueInLinkedList(policy_cache,0, + RemoveElementByValueFromLinkedList(policy_cache,p)); UnlockSemaphoreInfo(policy_semaphore); return(p); } @@ -258,21 +352,21 @@ MagickExport const PolicyInfo **GetPolicyInfoList(const char *pattern, if (p == (const PolicyInfo *) NULL) return((const PolicyInfo **) NULL); policies=(const PolicyInfo **) AcquireQuantumMemory((size_t) - GetNumberOfElementsInLinkedList(policy_list)+1UL,sizeof(*policies)); + GetNumberOfElementsInLinkedList(policy_cache)+1UL,sizeof(*policies)); if (policies == (const PolicyInfo **) NULL) return((const PolicyInfo **) NULL); /* Generate policy list. */ LockSemaphoreInfo(policy_semaphore); - ResetLinkedListIterator(policy_list); - p=(const PolicyInfo *) GetNextValueInLinkedList(policy_list); + ResetLinkedListIterator(policy_cache); + p=(const PolicyInfo *) GetNextValueInLinkedList(policy_cache); for (i=0; p != (const PolicyInfo *) NULL; ) { if ((p->stealth == MagickFalse) && (GlobExpression(p->name,pattern,MagickFalse) != MagickFalse)) policies[i++]=p; - p=(const PolicyInfo *) GetNextValueInLinkedList(policy_list); + p=(const PolicyInfo *) GetNextValueInLinkedList(policy_cache); } UnlockSemaphoreInfo(policy_semaphore); policies[i]=(PolicyInfo *) NULL; @@ -330,21 +424,21 @@ MagickExport char **GetPolicyList(const char *pattern, if (p == (const PolicyInfo *) NULL) return((char **) NULL); policies=(char **) AcquireQuantumMemory((size_t) - GetNumberOfElementsInLinkedList(policy_list)+1UL,sizeof(*policies)); + GetNumberOfElementsInLinkedList(policy_cache)+1UL,sizeof(*policies)); if (policies == (char **) NULL) return((char **) NULL); /* Generate policy list. */ LockSemaphoreInfo(policy_semaphore); - ResetLinkedListIterator(policy_list); - p=(const PolicyInfo *) GetNextValueInLinkedList(policy_list); + ResetLinkedListIterator(policy_cache); + p=(const PolicyInfo *) GetNextValueInLinkedList(policy_cache); for (i=0; p != (const PolicyInfo *) NULL; ) { if ((p->stealth == MagickFalse) && (GlobExpression(p->name,pattern,MagickFalse) != MagickFalse)) policies[i++]=ConstantString(p->name); - p=(const PolicyInfo *) GetNextValueInLinkedList(policy_list); + p=(const PolicyInfo *) GetNextValueInLinkedList(policy_cache); } UnlockSemaphoreInfo(policy_semaphore); policies[i]=(char *) NULL; @@ -403,33 +497,36 @@ MagickExport char *GetPolicyValue(const char *name) % % % % % % -+ I s P o l i c y L i s t I n s t a n t i a t e d % ++ I s P o l i c y C a c h e I n s t a n t i a t e d % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % -% IsPolicyListInstantiated() determines if the policy list is instantiated. +% IsPolicyCacheInstantiated() determines if the policy list is instantiated. % If not, it instantiates the list and returns it. % % The format of the IsPolicyInstantiated method is: % -% MagickBooleanType IsPolicyListInstantiated(ExceptionInfo *exception) +% MagickBooleanType IsPolicyCacheInstantiated(ExceptionInfo *exception) % % A description of each parameter follows. % % o exception: return any errors or warnings in this structure. % */ -static MagickBooleanType IsPolicyListInstantiated(ExceptionInfo *exception) +static MagickBooleanType IsPolicyCacheInstantiated(ExceptionInfo *exception) { - if (policy_semaphore == (SemaphoreInfo *) NULL) - ActivateSemaphoreInfo(&policy_semaphore); - LockSemaphoreInfo(policy_semaphore); - if (policy_list == (LinkedListInfo *) NULL) - (void) LoadPolicyLists(PolicyFilename,exception); - UnlockSemaphoreInfo(policy_semaphore); - return(policy_list != (LinkedListInfo *) NULL ? MagickTrue : MagickFalse); + if (policy_cache == (LinkedListInfo *) NULL) + { + if (policy_semaphore == (SemaphoreInfo *) NULL) + ActivateSemaphoreInfo(&policy_semaphore); + LockSemaphoreInfo(policy_semaphore); + if (policy_cache == (LinkedListInfo *) NULL) + policy_cache=AcquirePolicyCache(PolicyFilename,exception); + UnlockSemaphoreInfo(policy_semaphore); + } + return(policy_cache != (LinkedListInfo *) NULL ? MagickTrue : MagickFalse); } /* @@ -486,8 +583,8 @@ MagickExport MagickBooleanType IsRightsAuthorized(const PolicyDomain domain, return(MagickTrue); authorized=MagickTrue; LockSemaphoreInfo(policy_semaphore); - ResetLinkedListIterator(policy_list); - p=(PolicyInfo *) GetNextValueInLinkedList(policy_list); + ResetLinkedListIterator(policy_cache); + p=(PolicyInfo *) GetNextValueInLinkedList(policy_cache); while ((p != (PolicyInfo *) NULL) && (authorized != MagickFalse)) { if ((p->domain == domain) && @@ -503,7 +600,7 @@ MagickExport MagickBooleanType IsRightsAuthorized(const PolicyDomain domain, ((p->rights & ExecutePolicyRights) == 0)) authorized=MagickFalse; } - p=(PolicyInfo *) GetNextValueInLinkedList(policy_list); + p=(PolicyInfo *) GetNextValueInLinkedList(policy_cache); } UnlockSemaphoreInfo(policy_semaphore); return(authorized); @@ -612,12 +709,12 @@ MagickExport MagickBooleanType ListPolicyInfo(FILE *file, % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % -% LoadPolicyList() loads the policy configuration file which provides a mapping +% LoadPolicyCache() loads the policy configurations which provides a mapping % between policy attributes and a policy domain. % -% The format of the LoadPolicyList method is: +% The format of the LoadPolicyCache method is: % -% MagickBooleanType LoadPolicyList(const char *xml,const char *filename, +% MagickBooleanType LoadPolicyCache(const char *xml,const char *filename, % const size_t depth,ExceptionInfo *exception) % % A description of each parameter follows: @@ -631,7 +728,7 @@ MagickExport MagickBooleanType ListPolicyInfo(FILE *file, % o exception: return any errors or warnings in this structure. % */ -static MagickBooleanType LoadPolicyList(const char *xml,const char *filename, +static MagickBooleanType LoadPolicyCache(const char *xml,const char *filename, const size_t depth,ExceptionInfo *exception) { char @@ -654,10 +751,10 @@ static MagickBooleanType LoadPolicyList(const char *xml,const char *filename, "Loading policy file \"%s\" ...",filename); if (xml == (char *) NULL) return(MagickFalse); - if (policy_list == (LinkedListInfo *) NULL) + if (policy_cache == (LinkedListInfo *) NULL) { - policy_list=NewLinkedList(0); - if (policy_list == (LinkedListInfo *) NULL) + policy_cache=NewLinkedList(0); + if (policy_cache == (LinkedListInfo *) NULL) { ThrowFileException(exception,ResourceLimitError, "MemoryAllocationFailed",filename); @@ -728,7 +825,7 @@ static MagickBooleanType LoadPolicyList(const char *xml,const char *filename, xml=FileToString(path,~0UL,exception); if (xml != (char *) NULL) { - status=LoadPolicyList(xml,path,depth+1,exception); + status=LoadPolicyCache(xml,path,depth+1,exception); xml=(char *) RelinquishMagickMemory(xml); } } @@ -754,7 +851,7 @@ static MagickBooleanType LoadPolicyList(const char *xml,const char *filename, continue; if (LocaleCompare(keyword,"/>") == 0) { - status=AppendValueToLinkedList(policy_list,policy_info); + status=AppendValueToLinkedList(policy_cache,policy_info); if (status == MagickFalse) (void) ThrowMagickException(exception,GetMagickModule(), ResourceLimitError,"MemoryAllocationFailed","`%s'", @@ -844,106 +941,6 @@ static MagickBooleanType LoadPolicyList(const char *xml,const char *filename, % % % % % % -% L o a d P o l i c y L i s t s % -% % -% % -% % -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% -% LoadPolicyList() loads one or more policy configuration file which provides a -% mapping between policy attributes and a policy name. -% -% The format of the LoadPolicyLists method is: -% -% MagickBooleanType LoadPolicyLists(const char *filename, -% ExceptionInfo *exception) -% -% A description of each parameter follows: -% -% o filename: the font file name. -% -% o exception: return any errors or warnings in this structure. -% -*/ -static MagickBooleanType LoadPolicyLists(const char *filename, - ExceptionInfo *exception) -{ - const StringInfo - *option; - - LinkedListInfo - *options; - - MagickStatusType - status; - - register ssize_t - i; - - /* - Load external policy map. - */ - if (policy_list == (LinkedListInfo *) NULL) - { - policy_list=NewLinkedList(0); - if (policy_list == (LinkedListInfo *) NULL) - { - ThrowFileException(exception,ResourceLimitError, - "MemoryAllocationFailed",filename); - return(MagickFalse); - } - } - status=MagickTrue; - options=GetConfigureOptions(filename,exception); - option=(const StringInfo *) GetNextValueInLinkedList(options); - while (option != (const StringInfo *) NULL) - { - status&=LoadPolicyList((const char *) GetStringInfoDatum(option), - GetStringInfoPath(option),0,exception); - option=(const StringInfo *) GetNextValueInLinkedList(options); - } - options=DestroyConfigureOptions(options); - /* - Load built-in policy map. - */ - for (i=0; i < (ssize_t) (sizeof(PolicyMap)/sizeof(*PolicyMap)); i++) - { - PolicyInfo - *policy_info; - - register const PolicyMapInfo - *p; - - p=PolicyMap+i; - policy_info=(PolicyInfo *) AcquireMagickMemory(sizeof(*policy_info)); - if (policy_info == (PolicyInfo *) NULL) - { - (void) ThrowMagickException(exception,GetMagickModule(), - ResourceLimitError,"MemoryAllocationFailed","`%s'",p->name); - continue; - } - (void) ResetMagickMemory(policy_info,0,sizeof(*policy_info)); - policy_info->path=(char *) "[built-in]"; - policy_info->domain=p->domain; - policy_info->rights=p->rights; - policy_info->name=(char *) p->name; - policy_info->pattern=(char *) p->pattern; - policy_info->value=(char *) p->value; - policy_info->exempt=MagickTrue; - policy_info->signature=MagickSignature; - status&=AppendValueToLinkedList(policy_list,policy_info); - if (status == MagickFalse) - (void) ThrowMagickException(exception,GetMagickModule(), - ResourceLimitError,"MemoryAllocationFailed","`%s'",policy_info->name); - } - return(status != 0 ? MagickTrue : MagickFalse); -} - -/* -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% % -% % -% % + P o l i c y C o m p o n e n t G e n e s i s % % % % % @@ -1008,8 +1005,8 @@ MagickPrivate void PolicyComponentTerminus(void) if (policy_semaphore == (SemaphoreInfo *) NULL) ActivateSemaphoreInfo(&policy_semaphore); LockSemaphoreInfo(policy_semaphore); - if (policy_list != (LinkedListInfo *) NULL) - policy_list=DestroyLinkedList(policy_list,DestroyPolicyElement); + if (policy_cache != (LinkedListInfo *) NULL) + policy_cache=DestroyLinkedList(policy_cache,DestroyPolicyElement); UnlockSemaphoreInfo(policy_semaphore); RelinquishSemaphoreInfo(&policy_semaphore); } diff --git a/MagickCore/type.c b/MagickCore/type.c index b727289d1..def5b3791 100644 --- a/MagickCore/type.c +++ b/MagickCore/type.c @@ -118,14 +118,132 @@ static SemaphoreInfo *type_semaphore = (SemaphoreInfo *) NULL; static SplayTreeInfo - *type_list = (SplayTreeInfo *) NULL; + *type_cache = (SplayTreeInfo *) NULL; /* Forward declarations. */ static MagickBooleanType IsTypeTreeInstantiated(ExceptionInfo *), - LoadTypeLists(const char *,ExceptionInfo *); + LoadTypeCache(const char *,const char *,const size_t,ExceptionInfo *); + +/* +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% % +% % +% % +% A c q u i r e T y p e S p l a y T r e e % +% % +% % +% % +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% AcquireTypeCache() caches one or more type configuration files which +% provides a mapping between type attributes and a type name. +% +% The format of the AcquireTypeCache method is: +% +% SplayTreeInfo *AcquireTypeCache(const char *filename, +% ExceptionInfo *exception) +% +% A description of each parameter follows: +% +% o filename: the font file name. +% +% o exception: return any errors or warnings in this structure. +% +*/ + +static void *DestroyTypeNode(void *type_info) +{ + register TypeInfo + *p; + + p=(TypeInfo *) type_info; + if (p->path != (char *) NULL) + p->path=DestroyString(p->path); + if (p->name != (char *) NULL) + p->name=DestroyString(p->name); + if (p->description != (char *) NULL) + p->description=DestroyString(p->description); + if (p->family != (char *) NULL) + p->family=DestroyString(p->family); + if (p->encoding != (char *) NULL) + p->encoding=DestroyString(p->encoding); + if (p->foundry != (char *) NULL) + p->foundry=DestroyString(p->foundry); + if (p->format != (char *) NULL) + p->format=DestroyString(p->format); + if (p->metrics != (char *) NULL) + p->metrics=DestroyString(p->metrics); + if (p->glyphs != (char *) NULL) + p->glyphs=DestroyString(p->glyphs); + return(RelinquishMagickMemory(p)); +} + +static SplayTreeInfo *AcquireTypeCache(const char *filename, + ExceptionInfo *exception) +{ +#if defined(MAGICKCORE_ZERO_CONFIGURATION_SUPPORT) + return(LoadTypeCache(TypeMap,"built-in",0,exception)); +#else + char + *font_path, + path[MaxTextExtent]; + + const StringInfo + *option; + + LinkedListInfo + *options; + + MagickStatusType + status; + + SplayTreeInfo + *type_cache; + + type_cache=NewSplayTree(CompareSplayTreeString,(void *(*)(void *)) NULL, + DestroyTypeNode); + if (type_cache == (SplayTreeInfo *) NULL) + ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); + status=MagickTrue; + *path='\0'; + options=GetConfigureOptions(filename,exception); + option=(const StringInfo *) GetNextValueInLinkedList(options); + while (option != (const StringInfo *) NULL) + { + (void) CopyMagickString(path,GetStringInfoPath(option),MaxTextExtent); + status&=LoadTypeCache((const char *) GetStringInfoDatum(option), + GetStringInfoPath(option),0,exception); + option=(const StringInfo *) GetNextValueInLinkedList(options); + } + options=DestroyConfigureOptions(options); + font_path=GetEnvironmentValue("MAGICK_FONT_PATH"); + if (font_path != (char *) NULL) + { + char + *option; + + /* + Search MAGICK_FONT_PATH. + */ + (void) FormatLocaleString(path,MaxTextExtent,"%s%s%s",font_path, + DirectorySeparator,filename); + option=FileToString(path,~0UL,exception); + if (option != (void *) NULL) + { + status&=LoadTypeCache(option,path,0,exception); + option=DestroyString(option); + } + font_path=DestroyString(font_path); + } + if ((type_cache == (SplayTreeInfo *) NULL) || + (GetNumberOfNodesInSplayTree(type_cache) == 0)) + status&=LoadTypeCache(TypeMap,"built-in",0,exception); + return(type_cache); +#endif +} /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -155,18 +273,21 @@ static MagickBooleanType MagickExport const TypeInfo *GetTypeInfo(const char *name, ExceptionInfo *exception) { + const TypeInfo + *type_info; + assert(exception != (ExceptionInfo *) NULL); if (IsTypeTreeInstantiated(exception) == MagickFalse) return((const TypeInfo *) NULL); LockSemaphoreInfo(type_semaphore); if ((name == (const char *) NULL) || (LocaleCompare(name,"*") == 0)) { - ResetSplayTreeIterator(type_list); - type_info=(const TypeInfo *) GetNextValueInSplayTree(type_list); + ResetSplayTreeIterator(type_cache); + type_info=(const TypeInfo *) GetNextValueInSplayTree(type_cache); UnlockSemaphoreInfo(type_semaphore); return(type_info); } - type_info=(const TypeInfo *) GetValueFromSplayTree(type_list,name); + type_info=(const TypeInfo *) GetValueFromSplayTree(type_cache,name); UnlockSemaphoreInfo(type_semaphore); return(type_info); } @@ -265,17 +386,17 @@ MagickExport const TypeInfo *GetTypeInfoByFamily(const char *family, Check for an exact type match. */ (void) GetTypeInfo("*",exception); - if (type_list == (SplayTreeInfo *) NULL) + if (type_cache == (SplayTreeInfo *) NULL) return((TypeInfo *) NULL); LockSemaphoreInfo(type_semaphore); - ResetSplayTreeIterator(type_list); + ResetSplayTreeIterator(type_cache); type_info=(const TypeInfo *) NULL; - p=(const TypeInfo *) GetNextValueInSplayTree(type_list); + p=(const TypeInfo *) GetNextValueInSplayTree(type_cache); while (p != (const TypeInfo *) NULL) { if (p->family == (char *) NULL) { - p=(const TypeInfo *) GetNextValueInSplayTree(type_list); + p=(const TypeInfo *) GetNextValueInSplayTree(type_cache); continue; } if (family == (const char *) NULL) @@ -283,30 +404,30 @@ MagickExport const TypeInfo *GetTypeInfoByFamily(const char *family, if ((LocaleCompare(p->family,"arial") != 0) && (LocaleCompare(p->family,"helvetica") != 0)) { - p=(const TypeInfo *) GetNextValueInSplayTree(type_list); + p=(const TypeInfo *) GetNextValueInSplayTree(type_cache); continue; } } else if (LocaleCompare(p->family,family) != 0) { - p=(const TypeInfo *) GetNextValueInSplayTree(type_list); + p=(const TypeInfo *) GetNextValueInSplayTree(type_cache); continue; } if ((style != UndefinedStyle) && (style != AnyStyle) && (p->style != style)) { - p=(const TypeInfo *) GetNextValueInSplayTree(type_list); + p=(const TypeInfo *) GetNextValueInSplayTree(type_cache); continue; } if ((stretch != UndefinedStretch) && (stretch != AnyStretch) && (p->stretch != stretch)) { - p=(const TypeInfo *) GetNextValueInSplayTree(type_list); + p=(const TypeInfo *) GetNextValueInSplayTree(type_cache); continue; } if ((weight != 0) && (p->weight != weight)) { - p=(const TypeInfo *) GetNextValueInSplayTree(type_list); + p=(const TypeInfo *) GetNextValueInSplayTree(type_cache); continue; } type_info=p; @@ -320,13 +441,13 @@ MagickExport const TypeInfo *GetTypeInfoByFamily(const char *family, */ max_score=0; LockSemaphoreInfo(type_semaphore); - ResetSplayTreeIterator(type_list); - p=(const TypeInfo *) GetNextValueInSplayTree(type_list); + ResetSplayTreeIterator(type_cache); + p=(const TypeInfo *) GetNextValueInSplayTree(type_cache); while (p != (const TypeInfo *) NULL) { if (p->family == (char *) NULL) { - p=(const TypeInfo *) GetNextValueInSplayTree(type_list); + p=(const TypeInfo *) GetNextValueInSplayTree(type_cache); continue; } if (family == (const char *) NULL) @@ -334,14 +455,14 @@ MagickExport const TypeInfo *GetTypeInfoByFamily(const char *family, if ((LocaleCompare(p->family,"arial") != 0) && (LocaleCompare(p->family,"helvetica") != 0)) { - p=(const TypeInfo *) GetNextValueInSplayTree(type_list); + p=(const TypeInfo *) GetNextValueInSplayTree(type_cache); continue; } } else if (LocaleCompare(p->family,family) != 0) { - p=(const TypeInfo *) GetNextValueInSplayTree(type_list); + p=(const TypeInfo *) GetNextValueInSplayTree(type_cache); continue; } score=0; @@ -369,7 +490,7 @@ MagickExport const TypeInfo *GetTypeInfoByFamily(const char *family, max_score=score; type_info=p; } - p=(const TypeInfo *) GetNextValueInSplayTree(type_list); + p=(const TypeInfo *) GetNextValueInSplayTree(type_cache); } UnlockSemaphoreInfo(type_semaphore); if (type_info != (const TypeInfo *) NULL) @@ -476,21 +597,21 @@ MagickExport const TypeInfo **GetTypeInfoList(const char *pattern, if (p == (const TypeInfo *) NULL) return((const TypeInfo **) NULL); fonts=(const TypeInfo **) AcquireQuantumMemory((size_t) - GetNumberOfNodesInSplayTree(type_list)+1UL,sizeof(*fonts)); + GetNumberOfNodesInSplayTree(type_cache)+1UL,sizeof(*fonts)); if (fonts == (const TypeInfo **) NULL) return((const TypeInfo **) NULL); /* Generate type list. */ LockSemaphoreInfo(type_semaphore); - ResetSplayTreeIterator(type_list); - p=(const TypeInfo *) GetNextValueInSplayTree(type_list); + ResetSplayTreeIterator(type_cache); + p=(const TypeInfo *) GetNextValueInSplayTree(type_cache); for (i=0; p != (const TypeInfo *) NULL; ) { if ((p->stealth == MagickFalse) && (GlobExpression(p->name,pattern,MagickFalse) != MagickFalse)) fonts[i++]=p; - p=(const TypeInfo *) GetNextValueInSplayTree(type_list); + p=(const TypeInfo *) GetNextValueInSplayTree(type_cache); } UnlockSemaphoreInfo(type_semaphore); qsort((void *) fonts,(size_t) i,sizeof(*fonts),TypeInfoCompare); @@ -569,21 +690,21 @@ MagickExport char **GetTypeList(const char *pattern,size_t *number_fonts, if (p == (const TypeInfo *) NULL) return((char **) NULL); fonts=(char **) AcquireQuantumMemory((size_t) - GetNumberOfNodesInSplayTree(type_list)+1UL,sizeof(*fonts)); + GetNumberOfNodesInSplayTree(type_cache)+1UL,sizeof(*fonts)); if (fonts == (char **) NULL) return((char **) NULL); /* Generate type list. */ LockSemaphoreInfo(type_semaphore); - ResetSplayTreeIterator(type_list); - p=(const TypeInfo *) GetNextValueInSplayTree(type_list); + ResetSplayTreeIterator(type_cache); + p=(const TypeInfo *) GetNextValueInSplayTree(type_cache); for (i=0; p != (const TypeInfo *) NULL; ) { if ((p->stealth == MagickFalse) && (GlobExpression(p->name,pattern,MagickFalse) != MagickFalse)) fonts[i++]=ConstantString(p->name); - p=(const TypeInfo *) GetNextValueInSplayTree(type_list); + p=(const TypeInfo *) GetNextValueInSplayTree(type_cache); } UnlockSemaphoreInfo(type_semaphore); qsort((void *) fonts,(size_t) i,sizeof(*fonts),TypeCompare); @@ -617,7 +738,7 @@ MagickExport char **GetTypeList(const char *pattern,size_t *number_fonts, */ #if defined(MAGICKCORE_FONTCONFIG_DELEGATE) -MagickExport MagickBooleanType LoadFontConfigFonts(SplayTreeInfo *type_list, +MagickExport MagickBooleanType LoadFontConfigFonts(SplayTreeInfo *type_cache, ExceptionInfo *exception) { #if !defined(FC_FULLNAME) @@ -770,7 +891,7 @@ MagickExport MagickBooleanType LoadFontConfigFonts(SplayTreeInfo *type_list, if (weight >= FC_WEIGHT_BLACK) type_info->weight=900; type_info->glyphs=ConstantString((const char *) file); - (void) AddValueToSplayTree(type_list,type_info->name,type_info); + (void) AddValueToSplayTree(type_cache,type_info->name,type_info); } FcFontSetDestroy(font_set); FcConfigDestroy(font_config); @@ -780,21 +901,24 @@ MagickExport MagickBooleanType LoadFontConfigFonts(SplayTreeInfo *type_list, static MagickBooleanType IsTypeTreeInstantiated(ExceptionInfo *exception) { - if (type_semaphore == (SemaphoreInfo *) NULL) - ActivateSemaphoreInfo(&type_semaphore); - LockSemaphoreInfo(type_semaphore); - if (type_list == (SplayTreeInfo *) NULL) + if (type_cache == (SplayTreeInfo *) NULL) { - (void) LoadTypeLists(MagickTypeFilename,exception); + if (type_semaphore == (SemaphoreInfo *) NULL) + ActivateSemaphoreInfo(&type_semaphore); + LockSemaphoreInfo(type_semaphore); + if (type_cache == (SplayTreeInfo *) NULL) + { + type_cache=AcquireTypeCache(MagickTypeFilename,exception); #if defined(MAGICKCORE_WINDOWS_SUPPORT) - (void) NTLoadTypeLists(type_list,exception); + (void) NTAcquireTypeCache(type_cache,exception); #endif #if defined(MAGICKCORE_FONTCONFIG_DELEGATE) - (void) LoadFontConfigFonts(type_list,exception); + (void) LoadFontConfigFonts(type_cache,exception); #endif + } + UnlockSemaphoreInfo(type_semaphore); } - UnlockSemaphoreInfo(type_semaphore); - return(type_list != (SplayTreeInfo *) NULL ? MagickTrue : MagickFalse); + return(type_cache != (SplayTreeInfo *) NULL ? MagickTrue : MagickFalse); } /* @@ -896,12 +1020,12 @@ MagickExport MagickBooleanType ListTypeInfo(FILE *file,ExceptionInfo *exception) % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % -% LoadTypeList() loads the type configuration file which provides a mapping +% LoadTypeCache() loads the type configurations which provides a mapping % between type attributes and a type name. % -% The format of the LoadTypeList method is: +% The format of the LoadTypeCache method is: % -% MagickBooleanType LoadTypeList(const char *xml,const char *filename, +% MagickBooleanType LoadTypeCache(const char *xml,const char *filename, % const size_t depth,ExceptionInfo *exception) % % A description of each parameter follows: @@ -916,35 +1040,8 @@ MagickExport MagickBooleanType ListTypeInfo(FILE *file,ExceptionInfo *exception) % */ -static void *DestroyTypeNode(void *type_info) -{ - register TypeInfo - *p; - - p=(TypeInfo *) type_info; - if (p->path != (char *) NULL) - p->path=DestroyString(p->path); - if (p->name != (char *) NULL) - p->name=DestroyString(p->name); - if (p->description != (char *) NULL) - p->description=DestroyString(p->description); - if (p->family != (char *) NULL) - p->family=DestroyString(p->family); - if (p->encoding != (char *) NULL) - p->encoding=DestroyString(p->encoding); - if (p->foundry != (char *) NULL) - p->foundry=DestroyString(p->foundry); - if (p->format != (char *) NULL) - p->format=DestroyString(p->format); - if (p->metrics != (char *) NULL) - p->metrics=DestroyString(p->metrics); - if (p->glyphs != (char *) NULL) - p->glyphs=DestroyString(p->glyphs); - return(RelinquishMagickMemory(p)); -} - static inline MagickBooleanType SetTypeNodePath(const char *filename, -char *font_path,const char *token,char **target) + char *font_path,const char *token,char **target) { char *path; @@ -980,7 +1077,7 @@ char *font_path,const char *token,char **target) return(MagickTrue); } -static MagickBooleanType LoadTypeList(const char *xml,const char *filename, +static MagickBooleanType LoadTypeCache(const char *xml,const char *filename, const size_t depth,ExceptionInfo *exception) { char @@ -1004,11 +1101,11 @@ static MagickBooleanType LoadTypeList(const char *xml,const char *filename, "Loading type configure file \"%s\" ...",filename); if (xml == (const char *) NULL) return(MagickFalse); - if (type_list == (SplayTreeInfo *) NULL) + if (type_cache == (SplayTreeInfo *) NULL) { - type_list=NewSplayTree(CompareSplayTreeString,(void *(*)(void *)) NULL, + type_cache=NewSplayTree(CompareSplayTreeString,(void *(*)(void *)) NULL, DestroyTypeNode); - if (type_list == (SplayTreeInfo *) NULL) + if (type_cache == (SplayTreeInfo *) NULL) { ThrowFileException(exception,ResourceLimitError, "MemoryAllocationFailed",filename); @@ -1093,7 +1190,7 @@ static MagickBooleanType LoadTypeList(const char *xml,const char *filename, sans_exception=DestroyExceptionInfo(sans_exception); if (xml != (char *) NULL) { - status=LoadTypeList(xml,path,depth+1,exception); + status=LoadTypeCache(xml,path,depth+1,exception); xml=(char *) RelinquishMagickMemory(xml); } } @@ -1118,7 +1215,7 @@ static MagickBooleanType LoadTypeList(const char *xml,const char *filename, continue; if (LocaleCompare(keyword,"/>") == 0) { - status=AddValueToSplayTree(type_list,type_info->name,type_info); + status=AddValueToSplayTree(type_cache,type_info->name,type_info); if (status == MagickFalse) (void) ThrowMagickException(exception,GetMagickModule(), ResourceLimitError,"MemoryAllocationFailed","`%s'",type_info->name); @@ -1255,89 +1352,6 @@ static MagickBooleanType LoadTypeList(const char *xml,const char *filename, % % % % % % -% L o a d T y p e L i s t s % -% % -% % -% % -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% -% LoadTypeList() loads one or more type configuration files which provides a -% mapping between type attributes and a type name. -% -% The format of the LoadTypeLists method is: -% -% MagickBooleanType LoadTypeLists(const char *filename, -% ExceptionInfo *exception) -% -% A description of each parameter follows: -% -% o filename: the font file name. -% -% o exception: return any errors or warnings in this structure. -% -*/ -static MagickBooleanType LoadTypeLists(const char *filename, - ExceptionInfo *exception) -{ -#if defined(MAGICKCORE_ZERO_CONFIGURATION_SUPPORT) - return(LoadTypeList(TypeMap,"built-in",0,exception)); -#else - char - *font_path, - path[MaxTextExtent]; - - const StringInfo - *option; - - LinkedListInfo - *options; - - MagickStatusType - status; - - status=MagickFalse; - *path='\0'; - options=GetConfigureOptions(filename,exception); - option=(const StringInfo *) GetNextValueInLinkedList(options); - while (option != (const StringInfo *) NULL) - { - (void) CopyMagickString(path,GetStringInfoPath(option),MaxTextExtent); - status&=LoadTypeList((const char *) GetStringInfoDatum(option), - GetStringInfoPath(option),0,exception); - option=(const StringInfo *) GetNextValueInLinkedList(options); - } - options=DestroyConfigureOptions(options); - font_path=GetEnvironmentValue("MAGICK_FONT_PATH"); - if (font_path != (char *) NULL) - { - char - *option; - - /* - Search MAGICK_FONT_PATH. - */ - (void) FormatLocaleString(path,MaxTextExtent,"%s%s%s",font_path, - DirectorySeparator,filename); - option=FileToString(path,~0UL,exception); - if (option != (void *) NULL) - { - status&=LoadTypeList(option,path,0,exception); - option=DestroyString(option); - } - font_path=DestroyString(font_path); - } - if ((type_list == (SplayTreeInfo *) NULL) || - (GetNumberOfNodesInSplayTree(type_list) == 0)) - status&=LoadTypeList(TypeMap,"built-in",0,exception); - return(status != 0 ? MagickTrue : MagickFalse); -#endif -} - -/* -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% % -% % -% % + T y p e C o m p o n e n t G e n e s i s % % % % % @@ -1380,8 +1394,8 @@ MagickPrivate void TypeComponentTerminus(void) if (type_semaphore == (SemaphoreInfo *) NULL) ActivateSemaphoreInfo(&type_semaphore); LockSemaphoreInfo(type_semaphore); - if (type_list != (SplayTreeInfo *) NULL) - type_list=DestroySplayTree(type_list); + if (type_cache != (SplayTreeInfo *) NULL) + type_cache=DestroySplayTree(type_cache); UnlockSemaphoreInfo(type_semaphore); RelinquishSemaphoreInfo(&type_semaphore); } -- 2.40.0