MagickPrivate MagickBooleanType ClearExceptionInfo(ExceptionInfo *exception, MagickBooleanType relinquish) { assert(exception != (ExceptionInfo *) NULL); assert(exception->signature == MagickSignature); if (exception->semaphore == (SemaphoreInfo *) NULL) ActivateSemaphoreInfo(&exception->semaphore); LockSemaphoreInfo(exception->semaphore); if (relinquish == MagickFalse) relinquish=exception->relinquish; exception->severity=UndefinedException; if (relinquish != MagickFalse) { exception->signature=(~MagickSignature); if (exception->exceptions != (void *) NULL) exception->exceptions=(void *) DestroyLinkedList((LinkedListInfo *) exception->exceptions,DestroyExceptionElement); } else if (exception->exceptions != (void *) NULL) ClearLinkedList((LinkedListInfo *) exception->exceptions, DestroyExceptionElement); UnlockSemaphoreInfo(exception->semaphore); if (relinquish != MagickFalse) DestroySemaphoreInfo(&exception->semaphore); return(relinquish); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % D e s t r o y E x c e p t i o n I n f o % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % DestroyExceptionInfo() deallocates memory associated with an exception. % % The format of the DestroyExceptionInfo method is: % % ExceptionInfo *DestroyExceptionInfo(ExceptionInfo *exception) % % A description of each parameter follows: % % o exception: the exception info. % */ MagickExport ExceptionInfo *DestroyExceptionInfo(ExceptionInfo *exception) { MagickBooleanType relinquish; assert(exception != (ExceptionInfo *) NULL); assert(exception->signature == MagickCoreSignature); if (exception->semaphore == (SemaphoreInfo *) NULL) ActivateSemaphoreInfo(&exception->semaphore); LockSemaphoreInfo(exception->semaphore); exception->severity=UndefinedException; if (exception->relinquish != MagickFalse) { exception->signature=(~MagickCoreSignature); if (exception->exceptions != (void *) NULL) exception->exceptions=(void *) DestroyLinkedList((LinkedListInfo *) exception->exceptions,DestroyExceptionElement); } else if (exception->exceptions != (void *) NULL) ClearLinkedList((LinkedListInfo *) exception->exceptions, DestroyExceptionElement); relinquish=exception->relinquish; UnlockSemaphoreInfo(exception->semaphore); if (relinquish != MagickFalse) { RelinquishSemaphoreInfo(&exception->semaphore); exception=(ExceptionInfo *) RelinquishMagickMemory(exception); } return(exception); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % + T y p e C o m p o n e n t T e r m i n u s % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % TypeComponentTerminus() destroy type component. % % The format of the TypeComponentTerminus method is: % % void TypeComponentTerminus(void) % */ MagickExport void TypeComponentTerminus(void) { if (type_semaphore == (SemaphoreInfo *) NULL) ActivateSemaphoreInfo(&type_semaphore); LockSemaphoreInfo(type_semaphore); if (type_cache != (SplayTreeInfo *) NULL) type_cache=DestroySplayTree(type_cache); UnlockSemaphoreInfo(type_semaphore); DestroySemaphoreInfo(&type_semaphore); }
MagickPrivate void PolicyComponentTerminus(void) { if (policy_semaphore == (SemaphoreInfo *) NULL) ActivateSemaphoreInfo(&policy_semaphore); LockSemaphoreInfo(policy_semaphore); if (policy_cache != (LinkedListInfo *) NULL) policy_cache=DestroyLinkedList(policy_cache,DestroyPolicyElement); UnlockSemaphoreInfo(policy_semaphore); RelinquishSemaphoreInfo(&policy_semaphore); }
MagickExport void MagicComponentTerminus(void) { if (magic_semaphore == (SemaphoreInfo *) NULL) ActivateSemaphoreInfo(&magic_semaphore); LockSemaphoreInfo(magic_semaphore); if (magic_cache != (LinkedListInfo *) NULL) magic_cache=DestroyLinkedList(magic_cache,DestroyMagicElement); UnlockSemaphoreInfo(magic_semaphore); DestroySemaphoreInfo(&magic_semaphore); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % + C o d e r C o m p o n e n t T e r m i n u s % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % CoderComponentTerminus() destroys the coder component. % % The format of the CoderComponentTerminus method is: % % CoderComponentTerminus(void) % */ MagickPrivate void CoderComponentTerminus(void) { if (coder_semaphore == (SemaphoreInfo *) NULL) ActivateSemaphoreInfo(&coder_semaphore); LockSemaphoreInfo(coder_semaphore); if (coder_cache != (SplayTreeInfo *) NULL) coder_cache=DestroySplayTree(coder_cache); UnlockSemaphoreInfo(coder_semaphore); RelinquishSemaphoreInfo(&coder_semaphore); }
MagickPrivate void MimeComponentTerminus(void) { if (mime_semaphore == (SemaphoreInfo *) NULL) ActivateSemaphoreInfo(&mime_semaphore); LockSemaphoreInfo(mime_semaphore); if (mime_cache != (LinkedListInfo *) NULL) mime_cache=DestroyLinkedList(mime_cache,DestroyMimeElement); UnlockSemaphoreInfo(mime_semaphore); RelinquishSemaphoreInfo(&mime_semaphore); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % L i s t M a g i c k R e s o u r c e I n f o % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % ListMagickResourceInfo() lists the resource info to a file. % % The format of the ListMagickResourceInfo method is: % % MagickBooleanType ListMagickResourceInfo(FILE *file, % ExceptionInfo *exception) % % A description of each parameter follows. % % o file: An pointer to a FILE. % % o exception: return any errors or warnings in this structure. % */ MagickExport MagickBooleanType ListMagickResourceInfo(FILE *file, ExceptionInfo *magick_unused(exception)) { char area_limit[MagickFormatExtent], disk_limit[MagickFormatExtent], height_limit[MagickFormatExtent], map_limit[MagickFormatExtent], memory_limit[MagickFormatExtent], time_limit[MagickFormatExtent], width_limit[MagickFormatExtent]; magick_unreferenced(exception); if (file == (const FILE *) NULL) file=stdout; if (resource_semaphore == (SemaphoreInfo *) NULL) ActivateSemaphoreInfo(&resource_semaphore); LockSemaphoreInfo(resource_semaphore); (void) FormatMagickSize(resource_info.width_limit,MagickFalse,"P", MagickFormatExtent,width_limit); (void) FormatMagickSize(resource_info.height_limit,MagickFalse,"P", MagickFormatExtent,height_limit); (void) FormatMagickSize(resource_info.area_limit,MagickFalse,"B", MagickFormatExtent,area_limit); (void) FormatMagickSize(resource_info.memory_limit,MagickTrue,"B", MagickFormatExtent,memory_limit); (void) FormatMagickSize(resource_info.map_limit,MagickTrue,"B", MagickFormatExtent,map_limit); (void) CopyMagickString(disk_limit,"unlimited",MagickFormatExtent); if (resource_info.disk_limit != MagickResourceInfinity) (void) FormatMagickSize(resource_info.disk_limit,MagickTrue,"B", MagickFormatExtent,disk_limit); (void) CopyMagickString(time_limit,"unlimited",MagickFormatExtent); if (resource_info.time_limit != MagickResourceInfinity) (void) FormatLocaleString(time_limit,MagickFormatExtent,"%.20g",(double) ((MagickOffsetType) resource_info.time_limit)); (void) FormatLocaleFile(file,"Resource limits:\n"); (void) FormatLocaleFile(file," Width: %s\n",width_limit); (void) FormatLocaleFile(file," Height: %s\n",height_limit); (void) FormatLocaleFile(file," Area: %s\n",area_limit); (void) FormatLocaleFile(file," Memory: %s\n",memory_limit); (void) FormatLocaleFile(file," Map: %s\n",map_limit); (void) FormatLocaleFile(file," Disk: %s\n",disk_limit); (void) FormatLocaleFile(file," File: %.20g\n",(double) ((MagickOffsetType) resource_info.file_limit)); (void) FormatLocaleFile(file," Thread: %.20g\n",(double) ((MagickOffsetType) resource_info.thread_limit)); (void) FormatLocaleFile(file," Throttle: %.20g\n",(double) ((MagickOffsetType) resource_info.throttle_limit)); (void) FormatLocaleFile(file," Time: %s\n",time_limit); (void) fflush(file); UnlockSemaphoreInfo(resource_semaphore); return(MagickTrue); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % D e s t r o y W a n d I d s % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % DestroyWandIds() deallocates memory associated with the wand id's. % % The format of the DestroyWandIds() method is: % % void DestroyWandIds(void) % % A description of each parameter follows: % */ WandExport void DestroyWandIds(void) { if (wand_semaphore == (SemaphoreInfo *) NULL) ActivateSemaphoreInfo(&wand_semaphore); LockSemaphoreInfo(wand_semaphore); if (wand_ids != (SplayTreeInfo *) NULL) wand_ids=DestroySplayTree(wand_ids); instantiate_wand=MagickFalse; UnlockSemaphoreInfo(wand_semaphore); DestroySemaphoreInfo(&wand_semaphore); }
MagickExport void ConfigureComponentTerminus(void) { if (configure_semaphore == (SemaphoreInfo *) NULL) ActivateSemaphoreInfo(&configure_semaphore); LockSemaphoreInfo(configure_semaphore); if (configure_cache != (LinkedListInfo *) NULL) configure_cache=DestroyLinkedList(configure_cache,DestroyConfigureElement); configure_cache=(LinkedListInfo *) NULL; UnlockSemaphoreInfo(configure_semaphore); DestroySemaphoreInfo(&configure_semaphore); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % R e g i s t r y C o m p o n e n t T e r m i n u s % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % RegistryComponentTerminus() destroys the registry component. % % The format of the DestroyDefines method is: % % void RegistryComponentTerminus(void) % */ MagickExport void RegistryComponentTerminus(void) { if (registry_semaphore == (SemaphoreInfo *) NULL) ActivateSemaphoreInfo(®istry_semaphore); LockSemaphoreInfo(registry_semaphore); if (IsEventLogging() != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); if (registry != (void *) NULL) registry=DestroySplayTree(registry); UnlockSemaphoreInfo(registry_semaphore); DestroySemaphoreInfo(®istry_semaphore); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % + I s C o d e r T r e e I n s t a n t i a t e d % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % IsCoderTreeInstantiated() determines if the coder tree is instantiated. If % not, it instantiates the tree and returns it. % % The format of the IsCoderInstantiated method is: % % MagickBooleanType IsCoderTreeInstantiated(ExceptionInfo *exception) % % A description of each parameter follows. % % o exception: return any errors or warnings in this structure. % */ static MagickBooleanType IsCoderTreeInstantiated(ExceptionInfo *exception) { if (coder_cache == (SplayTreeInfo *) NULL) { if (coder_semaphore == (SemaphoreInfo *) NULL) ActivateSemaphoreInfo(&coder_semaphore); LockSemaphoreInfo(coder_semaphore); if (coder_cache == (SplayTreeInfo *) NULL) coder_cache=AcquireCoderCache(MagickCoderFilename,exception); UnlockSemaphoreInfo(coder_semaphore); } return(coder_cache != (SplayTreeInfo *) NULL ? MagickTrue : MagickFalse); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % + I s M a g i c C a c h e I n s t a n t i a t e d % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % 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 IsMagicCacheInstantiated(ExceptionInfo *exception) % % A description of each parameter follows. % % o exception: return any errors or warnings in this structure. % */ static MagickBooleanType IsMagicCacheInstantiated(ExceptionInfo *exception) { 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); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % + 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 % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % 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 IsPolicyCacheInstantiated(ExceptionInfo *exception) % % A description of each parameter follows. % % o exception: return any errors or warnings in this structure. % */ static MagickBooleanType IsPolicyCacheInstantiated(ExceptionInfo *exception) { 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); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % + 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 % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % 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 IsConfigureCacheInstantiated(ExceptionInfo *exception) % % A description of each parameter follows. % % o exception: return any errors or warnings in this structure. % */ static MagickBooleanType IsConfigureCacheInstantiated(ExceptionInfo *exception) { 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); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % A c q u i r e W a n d I d % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % AcquireWandId() returns a unique wand id. % % The format of the AcquireWandId() method is: % % size_t AcquireWandId() % */ WandExport size_t AcquireWandId(void) { static size_t id = 0; if (wand_semaphore == (SemaphoreInfo *) NULL) ActivateSemaphoreInfo(&wand_semaphore); LockSemaphoreInfo(wand_semaphore); if (wand_ids == (SplayTreeInfo *) NULL) wand_ids=NewSplayTree((int (*)(const void *,const void *)) NULL, (void *(*)(void *)) NULL,(void *(*)(void *)) NULL); id++; (void) AddValueToSplayTree(wand_ids,(const void *) id,(const void *) id); instantiate_wand=MagickTrue; UnlockSemaphoreInfo(wand_semaphore); return(id); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % A c q u i r e M a g i c k M e m o r y % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % AcquireMagickMemory() returns a pointer to a block of memory at least size % bytes suitably aligned for any use. % % The format of the AcquireMagickMemory method is: % % void *AcquireMagickMemory(const size_t size) % % A description of each parameter follows: % % o size: the size of the memory in bytes to allocate. % */ MagickExport void *AcquireMagickMemory(const size_t size) { register void *memory; #if !defined(MAGICKCORE_ZERO_CONFIGURATION_SUPPORT) memory=memory_methods.acquire_memory_handler(size == 0 ? 1UL : size); #else if (memory_semaphore == (SemaphoreInfo *) NULL) ActivateSemaphoreInfo(&memory_semaphore); if (free_segments == (DataSegmentInfo *) NULL) { LockSemaphoreInfo(memory_semaphore); if (free_segments == (DataSegmentInfo *) NULL) { register ssize_t i; assert(2*sizeof(size_t) > (size_t) (~SizeMask)); (void) ResetMagickMemory(&memory_pool,0,sizeof(memory_pool)); memory_pool.allocation=SegmentSize; memory_pool.blocks[MaxBlocks]=(void *) (-1); for (i=0; i < MaxSegments; i++) { if (i != 0) memory_pool.segment_pool[i].previous= (&memory_pool.segment_pool[i-1]); if (i != (MaxSegments-1)) memory_pool.segment_pool[i].next=(&memory_pool.segment_pool[i+1]); } free_segments=(&memory_pool.segment_pool[0]); } UnlockSemaphoreInfo(memory_semaphore); } LockSemaphoreInfo(memory_semaphore); memory=AcquireBlock(size == 0 ? 1UL : size); if (memory == (void *) NULL) { if (ExpandHeap(size == 0 ? 1UL : size) != MagickFalse) memory=AcquireBlock(size == 0 ? 1UL : size); } UnlockSemaphoreInfo(memory_semaphore); #endif return(memory); }
static MagickBooleanType IsTypeTreeInstantiated(ExceptionInfo *exception) { if (type_cache == (SplayTreeInfo *) NULL) { 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) NTAcquireTypeCache(type_cache,exception); #endif #if defined(MAGICKCORE_FONTCONFIG_DELEGATE) (void) LoadFontConfigFonts(type_cache,exception); #endif } UnlockSemaphoreInfo(type_semaphore); } return(type_cache != (SplayTreeInfo *) NULL ? MagickTrue : MagickFalse); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % + D e s t r o y M a g i c k M e m o r y % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % DestroyMagickMemory() deallocates memory associated with the memory manager. % % The format of the DestroyMagickMemory method is: % % DestroyMagickMemory(void) % */ MagickExport void DestroyMagickMemory(void) { #if defined(MAGICKCORE_ZERO_CONFIGURATION_SUPPORT) register ssize_t i; if (memory_semaphore == (SemaphoreInfo *) NULL) ActivateSemaphoreInfo(&memory_semaphore); LockSemaphoreInfo(memory_semaphore); for (i=0; i < (ssize_t) memory_pool.number_segments; i++) if (memory_pool.segments[i]->mapped == MagickFalse) memory_methods.destroy_memory_handler( memory_pool.segments[i]->allocation); else (void) UnmapBlob(memory_pool.segments[i]->allocation, memory_pool.segments[i]->length); free_segments=(DataSegmentInfo *) NULL; (void) ResetMagickMemory(&memory_pool,0,sizeof(memory_pool)); UnlockSemaphoreInfo(memory_semaphore); DestroySemaphoreInfo(&memory_semaphore); #endif }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % R e l i n q u i s h U n i q u e F i l e R e s o u r c e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % RelinquishUniqueFileResource() relinquishes a unique file resource. % % The format of the RelinquishUniqueFileResource() method is: % % MagickBooleanType RelinquishUniqueFileResource(const char *path) % % A description of each parameter follows: % % o name: the name of the temporary resource. % */ MagickExport MagickBooleanType RelinquishUniqueFileResource(const char *path) { char cache_path[MagickPathExtent]; MagickBooleanType status; assert(path != (const char *) NULL); status=MagickFalse; (void) LogMagickEvent(ResourceEvent,GetMagickModule(),"%s",path); if (resource_semaphore == (SemaphoreInfo *) NULL) ActivateSemaphoreInfo(&resource_semaphore); LockSemaphoreInfo(resource_semaphore); if (temporary_resources != (SplayTreeInfo *) NULL) status=DeleteNodeFromSplayTree(temporary_resources, (const void *) path); UnlockSemaphoreInfo(resource_semaphore); (void) CopyMagickString(cache_path,path,MagickPathExtent); AppendImageFormat("cache",cache_path); (void) ShredFile(cache_path); if (status == MagickFalse) status=ShredFile(path); return(status); }
MagickExport MagickBooleanType SetImageRegistry(const RegistryType type, const char *key,const void *value,ExceptionInfo *exception) { MagickBooleanType status; RegistryInfo *registry_info; void *clone_value; if (IsEventLogging() != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",key); if (value == (const void *) NULL) return(MagickFalse); clone_value=(void *) NULL; switch (type) { case StringRegistryType: default: { const char *string; string=(const char *) value; clone_value=(void *) ConstantString(string); break; } case ImageRegistryType: { const Image *image; image=(const Image *) value; if (image->signature != MagickSignature) { (void) ThrowMagickException(exception,GetMagickModule(),RegistryError, "UnableToSetRegistry","%s",key); return(MagickFalse); } clone_value=(void *) CloneImageList(image,exception); break; } case ImageInfoRegistryType: { const ImageInfo *image_info; image_info=(const ImageInfo *) value; if (image_info->signature != MagickSignature) { (void) ThrowMagickException(exception,GetMagickModule(),RegistryError, "UnableToSetRegistry","%s",key); return(MagickFalse); } clone_value=(void *) CloneImageInfo(image_info); break; } } if (clone_value == (void *) NULL) return(MagickFalse); registry_info=(RegistryInfo *) AcquireMagickMemory(sizeof(*registry_info)); if (registry_info == (RegistryInfo *) NULL) ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); (void) ResetMagickMemory(registry_info,0,sizeof(*registry_info)); registry_info->type=type; registry_info->value=clone_value; registry_info->signature=MagickSignature; if (registry == (SplayTreeInfo *) NULL) { if (registry_semaphore == (SemaphoreInfo *) NULL) ActivateSemaphoreInfo(®istry_semaphore); LockSemaphoreInfo(registry_semaphore); if (registry == (SplayTreeInfo *) NULL) registry=NewSplayTree(CompareSplayTreeString,RelinquishMagickMemory, DestroyRegistryNode); UnlockSemaphoreInfo(registry_semaphore); } status=AddValueToSplayTree(registry,ConstantString(key),registry_info); return(status); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % R e l i n q u i s h M a g i c k R e s o u r c e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % RelinquishMagickResource() relinquishes resources of the specified type. % % The format of the RelinquishMagickResource() method is: % % void RelinquishMagickResource(const ResourceType type, % const MagickSizeType size) % % A description of each parameter follows: % % o type: the type of resource. % % o size: the size of the resource. % */ MagickExport void RelinquishMagickResource(const ResourceType type, const MagickSizeType size) { char resource_current[MagickFormatExtent], resource_limit[MagickFormatExtent], resource_request[MagickFormatExtent]; (void) FormatMagickSize(size,MagickFalse,"B",MagickFormatExtent, resource_request); if (resource_semaphore == (SemaphoreInfo *) NULL) ActivateSemaphoreInfo(&resource_semaphore); LockSemaphoreInfo(resource_semaphore); switch (type) { case WidthResource: { resource_info.width=(MagickOffsetType) size; (void) FormatMagickSize((MagickSizeType) resource_info.width,MagickFalse, "P",MagickFormatExtent,resource_current); (void) FormatMagickSize(resource_info.width_limit,MagickFalse,"P", MagickFormatExtent,resource_limit); break; } case HeightResource: { resource_info.height=(MagickOffsetType) size; (void) FormatMagickSize((MagickSizeType) resource_info.height,MagickFalse, "P",MagickFormatExtent,resource_current); (void) FormatMagickSize(resource_info.height_limit,MagickFalse,"P", MagickFormatExtent,resource_limit); break; } case AreaResource: { resource_info.area=(MagickOffsetType) size; (void) FormatMagickSize((MagickSizeType) resource_info.area,MagickFalse, "B",MagickFormatExtent,resource_current); (void) FormatMagickSize(resource_info.area_limit,MagickFalse,"B", MagickFormatExtent,resource_limit); break; } case MemoryResource: { resource_info.memory-=size; (void) FormatMagickSize((MagickSizeType) resource_info.memory, MagickTrue,"B",MagickFormatExtent,resource_current); (void) FormatMagickSize(resource_info.memory_limit,MagickTrue,"B", MagickFormatExtent,resource_limit); break; } case MapResource: { resource_info.map-=size; (void) FormatMagickSize((MagickSizeType) resource_info.map,MagickTrue, "B",MagickFormatExtent,resource_current); (void) FormatMagickSize(resource_info.map_limit,MagickTrue,"B", MagickFormatExtent,resource_limit); break; } case DiskResource: { resource_info.disk-=size; (void) FormatMagickSize((MagickSizeType) resource_info.disk,MagickTrue, "B",MagickFormatExtent,resource_current); (void) FormatMagickSize(resource_info.disk_limit,MagickTrue,"B", MagickFormatExtent,resource_limit); break; } case FileResource: { resource_info.file-=size; (void) FormatMagickSize((MagickSizeType) resource_info.file,MagickFalse, "B",MagickFormatExtent,resource_current); (void) FormatMagickSize((MagickSizeType) resource_info.file_limit, MagickFalse,"B",MagickFormatExtent,resource_limit); break; } case ThreadResource: { (void) FormatMagickSize((MagickSizeType) resource_info.thread,MagickFalse, "B",MagickFormatExtent,resource_current); (void) FormatMagickSize((MagickSizeType) resource_info.thread_limit, MagickFalse,"B",MagickFormatExtent,resource_limit); break; } case ThrottleResource: { (void) FormatMagickSize((MagickSizeType) resource_info.throttle, MagickFalse,"B",MagickFormatExtent,resource_current); (void) FormatMagickSize((MagickSizeType) resource_info.throttle_limit, MagickFalse,"B",MagickFormatExtent,resource_limit); break; } case TimeResource: { resource_info.time-=size; (void) FormatMagickSize((MagickSizeType) resource_info.time,MagickFalse, "B",MagickFormatExtent,resource_current); (void) FormatMagickSize((MagickSizeType) resource_info.time_limit, MagickFalse,"B",MagickFormatExtent,resource_limit); break; } default: break; } UnlockSemaphoreInfo(resource_semaphore); (void) LogMagickEvent(ResourceEvent,GetMagickModule(),"%s: %s/%s/%s", CommandOptionToMnemonic(MagickResourceOptions,(ssize_t) type), resource_request,resource_current,resource_limit); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % G e t M a g i c k R e s o u r c e L i m i t % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % GetMagickResourceLimit() returns the specified resource limit. % % The format of the GetMagickResourceLimit() method is: % % MagickSizeType GetMagickResourceLimit(const ResourceType type) % % A description of each parameter follows: % % o type: the type of resource. % */ MagickExport MagickSizeType GetMagickResourceLimit(const ResourceType type) { MagickSizeType resource; resource=0; if (resource_semaphore == (SemaphoreInfo *) NULL) ActivateSemaphoreInfo(&resource_semaphore); LockSemaphoreInfo(resource_semaphore); switch (type) { case WidthResource: { resource=resource_info.width_limit; break; } case HeightResource: { resource=resource_info.height_limit; break; } case AreaResource: { resource=resource_info.area_limit; break; } case MemoryResource: { resource=resource_info.memory_limit; break; } case MapResource: { resource=resource_info.map_limit; break; } case DiskResource: { resource=resource_info.disk_limit; break; } case FileResource: { resource=resource_info.file_limit; break; } case ThreadResource: { resource=resource_info.thread_limit; break; } case ThrottleResource: { resource=resource_info.throttle_limit; break; } case TimeResource: { resource=resource_info.time_limit; break; } default: break; } UnlockSemaphoreInfo(resource_semaphore); return(resource); }
MagickExport int AcquireUniqueFileResource(char *path) { #if !defined(O_NOFOLLOW) #define O_NOFOLLOW 0 #endif #if !defined(TMP_MAX) # define TMP_MAX 238328 #endif int c, file; register char *p; register ssize_t i; static const char portable_filename[65] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-"; StringInfo *key; unsigned char *datum; assert(path != (char *) NULL); (void) LogMagickEvent(ResourceEvent,GetMagickModule(),"..."); if (random_info == (RandomInfo *) NULL) { LockSemaphoreInfo(resource_semaphore); if (random_info == (RandomInfo *) NULL) random_info=AcquireRandomInfo(); UnlockSemaphoreInfo(resource_semaphore); } file=(-1); for (i=0; i < (ssize_t) TMP_MAX; i++) { /* Get temporary pathname. */ (void) GetPathTemplate(path); key=GetRandomKey(random_info,6); p=path+strlen(path)-12; datum=GetStringInfoDatum(key); for (i=0; i < (ssize_t) GetStringInfoLength(key); i++) { c=(int) (datum[i] & 0x3f); *p++=portable_filename[c]; } key=DestroyStringInfo(key); #if defined(MAGICKCORE_HAVE_MKSTEMP) file=mkstemp(path); if (file != -1) { #if defined(MAGICKCORE_HAVE_FCHMOD) (void) fchmod(file,0600); #endif #if defined(__OS2__) setmode(file,O_BINARY); #endif break; } #endif key=GetRandomKey(random_info,12); p=path+strlen(path)-12; datum=GetStringInfoDatum(key); for (i=0; i < (ssize_t) GetStringInfoLength(key); i++) { c=(int) (datum[i] & 0x3f); *p++=portable_filename[c]; } key=DestroyStringInfo(key); file=open_utf8(path,O_RDWR | O_CREAT | O_EXCL | O_BINARY | O_NOFOLLOW, S_MODE); if ((file >= 0) || (errno != EEXIST)) break; } (void) LogMagickEvent(ResourceEvent,GetMagickModule(),"%s",path); if (file == -1) return(file); if (resource_semaphore == (SemaphoreInfo *) NULL) ActivateSemaphoreInfo(&resource_semaphore); LockSemaphoreInfo(resource_semaphore); if (temporary_resources == (SplayTreeInfo *) NULL) temporary_resources=NewSplayTree(CompareSplayTreeString, DestroyTemporaryResources,(void *(*)(void *)) NULL); UnlockSemaphoreInfo(resource_semaphore); (void) AddValueToSplayTree(temporary_resources,ConstantString(path), (const void *) NULL); return(file); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % A c q u i r e M a g i c k R e s o u r c e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % AcquireMagickResource() acquires resources of the specified type. % MagickFalse is returned if the specified resource is exhausted otherwise % MagickTrue. % % The format of the AcquireMagickResource() method is: % % MagickBooleanType AcquireMagickResource(const ResourceType type, % const MagickSizeType size) % % A description of each parameter follows: % % o type: the type of resource. % % o size: the number of bytes needed from for this resource. % */ MagickExport MagickBooleanType AcquireMagickResource(const ResourceType type, const MagickSizeType size) { char resource_current[MagickFormatExtent], resource_limit[MagickFormatExtent], resource_request[MagickFormatExtent]; MagickBooleanType status; MagickSizeType limit; status=MagickFalse; (void) FormatMagickSize(size,MagickFalse,"B",MagickFormatExtent, resource_request); if (resource_semaphore == (SemaphoreInfo *) NULL) ActivateSemaphoreInfo(&resource_semaphore); LockSemaphoreInfo(resource_semaphore); switch (type) { case AreaResource: { resource_info.area=(MagickOffsetType) size; limit=resource_info.area_limit; status=(resource_info.area_limit == MagickResourceInfinity) || (size < limit) ? MagickTrue : MagickFalse; (void) FormatMagickSize((MagickSizeType) resource_info.area,MagickFalse, "B",MagickFormatExtent,resource_current); (void) FormatMagickSize(resource_info.area_limit,MagickFalse,"B", MagickFormatExtent,resource_limit); break; } case MemoryResource: { resource_info.memory+=size; limit=resource_info.memory_limit; status=(resource_info.memory_limit == MagickResourceInfinity) || ((MagickSizeType) resource_info.memory < limit) ? MagickTrue : MagickFalse; (void) FormatMagickSize((MagickSizeType) resource_info.memory,MagickTrue, "B",MagickFormatExtent,resource_current); (void) FormatMagickSize(resource_info.memory_limit,MagickTrue,"B", MagickFormatExtent,resource_limit); break; } case MapResource: { resource_info.map+=size; limit=resource_info.map_limit; status=(resource_info.map_limit == MagickResourceInfinity) || ((MagickSizeType) resource_info.map < limit) ? MagickTrue : MagickFalse; (void) FormatMagickSize((MagickSizeType) resource_info.map,MagickTrue, "B",MagickFormatExtent,resource_current); (void) FormatMagickSize(resource_info.map_limit,MagickTrue,"B", MagickFormatExtent,resource_limit); break; } case DiskResource: { resource_info.disk+=size; limit=resource_info.disk_limit; status=(resource_info.disk_limit == MagickResourceInfinity) || ((MagickSizeType) resource_info.disk < limit) ? MagickTrue : MagickFalse; (void) FormatMagickSize((MagickSizeType) resource_info.disk,MagickTrue, "B",MagickFormatExtent,resource_current); (void) FormatMagickSize(resource_info.disk_limit,MagickTrue,"B", MagickFormatExtent,resource_limit); break; } case FileResource: { resource_info.file+=size; limit=resource_info.file_limit; status=(resource_info.file_limit == MagickResourceInfinity) || ((MagickSizeType) resource_info.file < limit) ? MagickTrue : MagickFalse; (void) FormatMagickSize((MagickSizeType) resource_info.file,MagickFalse, "B",MagickFormatExtent,resource_current); (void) FormatMagickSize((MagickSizeType) resource_info.file_limit, MagickFalse,"B",MagickFormatExtent,resource_limit); break; } case HeightResource: { resource_info.area=(MagickOffsetType) size; limit=resource_info.height_limit; status=(resource_info.area_limit == MagickResourceInfinity) || (size < limit) ? MagickTrue : MagickFalse; (void) FormatMagickSize((MagickSizeType) resource_info.height,MagickFalse, "P",MagickFormatExtent,resource_current); (void) FormatMagickSize(resource_info.height_limit,MagickFalse,"P", MagickFormatExtent,resource_limit); break; } case ThreadResource: { limit=resource_info.thread_limit; status=(resource_info.thread_limit == MagickResourceInfinity) || ((MagickSizeType) resource_info.thread < limit) ? MagickTrue : MagickFalse; (void) FormatMagickSize((MagickSizeType) resource_info.thread,MagickFalse, "B",MagickFormatExtent,resource_current); (void) FormatMagickSize((MagickSizeType) resource_info.thread_limit, MagickFalse,"B",MagickFormatExtent,resource_limit); break; } case ThrottleResource: { limit=resource_info.throttle_limit; status=(resource_info.throttle_limit == MagickResourceInfinity) || ((MagickSizeType) resource_info.throttle < limit) ? MagickTrue : MagickFalse; (void) FormatMagickSize((MagickSizeType) resource_info.throttle, MagickFalse,"B",MagickFormatExtent,resource_current); (void) FormatMagickSize((MagickSizeType) resource_info.throttle_limit, MagickFalse,"B",MagickFormatExtent,resource_limit); break; } case TimeResource: { resource_info.time+=size; limit=resource_info.time_limit; status=(resource_info.time_limit == MagickResourceInfinity) || ((MagickSizeType) resource_info.time < limit) ? MagickTrue : MagickFalse; (void) FormatMagickSize((MagickSizeType) resource_info.time,MagickFalse, "B",MagickFormatExtent,resource_current); (void) FormatMagickSize((MagickSizeType) resource_info.time_limit, MagickFalse,"B",MagickFormatExtent,resource_limit); break; } case WidthResource: { resource_info.area=(MagickOffsetType) size; limit=resource_info.width_limit; status=(resource_info.area_limit == MagickResourceInfinity) || (size < limit) ? MagickTrue : MagickFalse; (void) FormatMagickSize((MagickSizeType) resource_info.width,MagickFalse, "P",MagickFormatExtent,resource_current); (void) FormatMagickSize(resource_info.width_limit,MagickFalse,"P", MagickFormatExtent,resource_limit); break; } default: break; } UnlockSemaphoreInfo(resource_semaphore); (void) LogMagickEvent(ResourceEvent,GetMagickModule(),"%s: %s/%s/%s", CommandOptionToMnemonic(MagickResourceOptions,(ssize_t) type), resource_request,resource_current,resource_limit); return(status); }