// Duplicates the zone of memory used by the plug-in in the new context static void DupPluginTransformList(struct _cmsContext_struct* ctx, const struct _cmsContext_struct* src) { _cmsTransformPluginChunkType newHead = { NULL }; _cmsTransformCollection* entry; _cmsTransformCollection* Anterior = NULL; _cmsTransformPluginChunkType* head = (_cmsTransformPluginChunkType*) src->chunks[TransformPlugin]; // Walk the list copying all nodes for (entry = head->TransformCollection; entry != NULL; entry = entry ->Next) { _cmsTransformCollection *newEntry = ( _cmsTransformCollection *) _cmsSubAllocDup(ctx ->MemPool, entry, sizeof(_cmsTransformCollection)); if (newEntry == NULL) return; // We want to keep the linked list order, so this is a little bit tricky newEntry -> Next = NULL; if (Anterior) Anterior -> Next = newEntry; Anterior = newEntry; if (newHead.TransformCollection == NULL) newHead.TransformCollection = newEntry; } ctx ->chunks[TransformPlugin] = _cmsSubAllocDup(ctx->MemPool, &newHead, sizeof(_cmsTransformPluginChunkType)); }
// Duplicates the zone of memory used by the plug-in in the new context static void DupPluginIntentsList(struct _cmsContext_struct* ctx, const struct _cmsContext_struct* src) { _cmsIntentsPluginChunkType newHead = { NULL }; cmsIntentsList* entry; cmsIntentsList* Anterior = NULL; _cmsIntentsPluginChunkType* head = (_cmsIntentsPluginChunkType*) src->chunks[IntentPlugin]; // Walk the list copying all nodes for (entry = head->Intents; entry != NULL; entry = entry ->Next) { cmsIntentsList *newEntry = ( cmsIntentsList *) _cmsSubAllocDup(ctx ->MemPool, entry, sizeof(cmsIntentsList)); if (newEntry == NULL) return; // We want to keep the linked list order, so this is a little bit tricky newEntry -> Next = NULL; if (Anterior) Anterior -> Next = newEntry; Anterior = newEntry; if (newHead.Intents == NULL) newHead.Intents = newEntry; } ctx ->chunks[IntentPlugin] = _cmsSubAllocDup(ctx->MemPool, &newHead, sizeof(_cmsIntentsPluginChunkType)); }
// Allocates memory for transform plugin factory void _cmsAllocTransformPluginChunk(struct _cmsContext_struct* ctx, const struct _cmsContext_struct* src) { if (src != NULL) { // Copy all linked list DupPluginTransformList(ctx, src); } else { static _cmsTransformPluginChunkType TransformPluginChunkType = { NULL }; ctx ->chunks[TransformPlugin] = _cmsSubAllocDup(ctx ->MemPool, &TransformPluginChunkType, sizeof(_cmsTransformPluginChunkType)); } }
void _cmsAllocIntentsPluginChunk(struct _cmsContext_struct* ctx, const struct _cmsContext_struct* src) { if (src != NULL) { // Copy all linked list DupPluginIntentsList(ctx, src); } else { static _cmsIntentsPluginChunkType IntentsPluginChunkType = { NULL }; ctx ->chunks[IntentPlugin] = _cmsSubAllocDup(ctx ->MemPool, &IntentsPluginChunkType, sizeof(_cmsIntentsPluginChunkType)); } }
// Init and duplicate observer adaptation state void _cmsAllocAdaptationStateChunk(struct _cmsContext_struct* ctx, const struct _cmsContext_struct* src) { static _cmsAdaptationStateChunkType AdaptationStateChunk = { DEFAULT_OBSERVER_ADAPTATION_STATE }; void* from; if (src != NULL) { from = src ->chunks[AdaptationStateContext]; } else { from = &AdaptationStateChunk; } ctx ->chunks[AdaptationStateContext] = _cmsSubAllocDup(ctx ->MemPool, from, sizeof(_cmsAdaptationStateChunkType)); }
// Init and duplicate alarm codes void _cmsAllocAlarmCodesChunk(struct _cmsContext_struct* ctx, const struct _cmsContext_struct* src) { static _cmsAlarmCodesChunkType AlarmCodesChunk = { DEFAULT_ALARM_CODES_VALUE }; void* from; if (src != NULL) { from = src ->chunks[AlarmCodesContext]; } else { from = &AlarmCodesChunk; } ctx ->chunks[AlarmCodesContext] = _cmsSubAllocDup(ctx ->MemPool, from, sizeof(_cmsAlarmCodesChunkType)); }
// Allocate and init mutex container. void _cmsAllocMutexPluginChunk(struct _cmsContext_struct* ctx, const struct _cmsContext_struct* src) { static _cmsMutexPluginChunkType MutexChunk = {defMtxCreate, defMtxDestroy, defMtxLock, defMtxUnlock }; void* from; if (src != NULL) { from = src ->chunks[MutexPlugin]; } else { from = &MutexChunk; } ctx ->chunks[MutexPlugin] = _cmsSubAllocDup(ctx ->MemPool, from, sizeof(_cmsMutexPluginChunkType)); }
// Allocates and inits error logger container for a given context. If src is NULL, only initializes the value // to the default. Otherwise, it duplicates the value. The interface is standard across all context clients void _cmsAllocLogErrorChunk(struct _cmsContext_struct* ctx, const struct _cmsContext_struct* src) { static _cmsLogErrorChunkType LogErrorChunk = { DefaultLogErrorHandlerFunction }; void* from; if (src != NULL) { from = src ->chunks[Logger]; } else { from = &LogErrorChunk; } ctx ->chunks[Logger] = _cmsSubAllocDup(ctx ->MemPool, from, sizeof(_cmsLogErrorChunkType)); }
// Reset and duplicate memory manager void _cmsAllocMemPluginChunk(struct _cmsContext_struct* ctx, const struct _cmsContext_struct* src) { _cmsAssert(ctx != NULL); if (src != NULL) { // Duplicate ctx ->chunks[MemPlugin] = _cmsSubAllocDup(ctx ->MemPool, src ->chunks[MemPlugin], sizeof(_cmsMemPluginChunkType)); } else { // To reset it, we use the default allocators, which cannot be overriden ctx ->chunks[MemPlugin] = &ctx ->DefaultMemoryManager; } }