< prev index next >

src/java.desktop/share/native/liblcms/cmserr.c

Print this page




  13  * version 2 for more details (a copy is included in the LICENSE file that
  14  * accompanied this code).
  15  *
  16  * You should have received a copy of the GNU General Public License version
  17  * 2 along with this work; if not, write to the Free Software Foundation,
  18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  *
  20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * questions.
  23  */
  24 
  25 // This file is available under and governed by the GNU General Public
  26 // License version 2 only, as published by the Free Software Foundation.
  27 // However, the following notice accompanied the original version of this
  28 // file:
  29 //
  30 //---------------------------------------------------------------------------------
  31 //
  32 //  Little Color Management System
  33 //  Copyright (c) 1998-2015 Marti Maria Saguer
  34 //
  35 // Permission is hereby granted, free of charge, to any person obtaining
  36 // a copy of this software and associated documentation files (the "Software"),
  37 // to deal in the Software without restriction, including without limitation
  38 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
  39 // and/or sell copies of the Software, and to permit persons to whom the Software
  40 // is furnished to do so, subject to the following conditions:
  41 //
  42 // The above copyright notice and this permission notice shall be included in
  43 // all copies or substantial portions of the Software.
  44 //
  45 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  46 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  47 // THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  48 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  49 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  50 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  51 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  52 //
  53 //---------------------------------------------------------------------------------


 210                                             };
 211 
 212 
 213 // Reset and duplicate memory manager
 214 void _cmsAllocMemPluginChunk(struct _cmsContext_struct* ctx, const struct _cmsContext_struct* src)
 215 {
 216     _cmsAssert(ctx != NULL);
 217 
 218     if (src != NULL) {
 219 
 220         // Duplicate
 221         ctx ->chunks[MemPlugin] = _cmsSubAllocDup(ctx ->MemPool, src ->chunks[MemPlugin], sizeof(_cmsMemPluginChunkType));
 222     }
 223     else {
 224 
 225         // To reset it, we use the default allocators, which cannot be overriden
 226         ctx ->chunks[MemPlugin] = &ctx ->DefaultMemoryManager;
 227     }
 228 }
 229 
 230 // Auxiliar to fill memory management functions from plugin (or context 0 defaults)
 231 void _cmsInstallAllocFunctions(cmsPluginMemHandler* Plugin, _cmsMemPluginChunkType* ptr)
 232 {
 233     if (Plugin == NULL) {
 234 
 235         memcpy(ptr, &_cmsMemPluginChunk, sizeof(_cmsMemPluginChunk));
 236     }
 237     else {
 238 
 239         ptr ->MallocPtr  = Plugin -> MallocPtr;
 240         ptr ->FreePtr    = Plugin -> FreePtr;
 241         ptr ->ReallocPtr = Plugin -> ReallocPtr;
 242 
 243         // Make sure we revert to defaults
 244         ptr ->MallocZeroPtr= _cmsMallocZeroDefaultFn;
 245         ptr ->CallocPtr    = _cmsCallocDefaultFn;
 246         ptr ->DupPtr       = _cmsDupDefaultFn;
 247 
 248         if (Plugin ->MallocZeroPtr != NULL) ptr ->MallocZeroPtr = Plugin -> MallocZeroPtr;
 249         if (Plugin ->CallocPtr != NULL)     ptr ->CallocPtr     = Plugin -> CallocPtr;
 250         if (Plugin ->DupPtr != NULL)        ptr ->DupPtr        = Plugin -> DupPtr;


 442 {
 443     void *NewPtr;
 444 
 445     // Dup of null pointer is also NULL
 446     if (ptr == NULL)
 447         return NULL;
 448 
 449     NewPtr = _cmsSubAlloc(s, size);
 450 
 451     if (ptr != NULL && NewPtr != NULL) {
 452         memcpy(NewPtr, ptr, size);
 453     }
 454 
 455     return NewPtr;
 456 }
 457 
 458 
 459 
 460 // Error logging ******************************************************************
 461 
 462 // There is no error handling at all. When a funtion fails, it returns proper value.
 463 // For example, all create functions does return NULL on failure. Other return FALSE
 464 // It may be interesting, for the developer, to know why the function is failing.
 465 // for that reason, lcms2 does offer a logging function. This function does recive
 466 // a ENGLISH string with some clues on what is going wrong. You can show this
 467 // info to the end user, or just create some sort of log.
 468 // The logging function should NOT terminate the program, as this obviously can leave
 469 // resources. It is the programmer's responsability to check each function return code
 470 // to make sure it didn't fail.
 471 
 472 // Error messages are limited to MAX_ERROR_MESSAGE_LEN
 473 
 474 #define MAX_ERROR_MESSAGE_LEN   1024
 475 
 476 // ---------------------------------------------------------------------------------------------------------
 477 
 478 // This is our default log error
 479 static void DefaultLogErrorHandlerFunction(cmsContext ContextID, cmsUInt32Number ErrorCode, const char *Text);
 480 
 481 // Context0 storage, which is global
 482 _cmsLogErrorChunkType _cmsLogErrorChunk = { DefaultLogErrorHandlerFunction };
 483 
 484 // Allocates and inits error logger container for a given context. If src is NULL, only initializes the value
 485 // to the default. Otherwise, it duplicates the value. The interface is standard across all context clients
 486 void _cmsAllocLogErrorChunk(struct _cmsContext_struct* ctx,
 487                             const struct _cmsContext_struct* src)
 488 {
 489     static _cmsLogErrorChunkType LogErrorChunk = { DefaultLogErrorHandlerFunction };




  13  * version 2 for more details (a copy is included in the LICENSE file that
  14  * accompanied this code).
  15  *
  16  * You should have received a copy of the GNU General Public License version
  17  * 2 along with this work; if not, write to the Free Software Foundation,
  18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  *
  20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * questions.
  23  */
  24 
  25 // This file is available under and governed by the GNU General Public
  26 // License version 2 only, as published by the Free Software Foundation.
  27 // However, the following notice accompanied the original version of this
  28 // file:
  29 //
  30 //---------------------------------------------------------------------------------
  31 //
  32 //  Little Color Management System
  33 //  Copyright (c) 1998-2016 Marti Maria Saguer
  34 //
  35 // Permission is hereby granted, free of charge, to any person obtaining
  36 // a copy of this software and associated documentation files (the "Software"),
  37 // to deal in the Software without restriction, including without limitation
  38 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
  39 // and/or sell copies of the Software, and to permit persons to whom the Software
  40 // is furnished to do so, subject to the following conditions:
  41 //
  42 // The above copyright notice and this permission notice shall be included in
  43 // all copies or substantial portions of the Software.
  44 //
  45 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  46 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  47 // THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  48 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  49 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  50 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  51 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  52 //
  53 //---------------------------------------------------------------------------------


 210                                             };
 211 
 212 
 213 // Reset and duplicate memory manager
 214 void _cmsAllocMemPluginChunk(struct _cmsContext_struct* ctx, const struct _cmsContext_struct* src)
 215 {
 216     _cmsAssert(ctx != NULL);
 217 
 218     if (src != NULL) {
 219 
 220         // Duplicate
 221         ctx ->chunks[MemPlugin] = _cmsSubAllocDup(ctx ->MemPool, src ->chunks[MemPlugin], sizeof(_cmsMemPluginChunkType));
 222     }
 223     else {
 224 
 225         // To reset it, we use the default allocators, which cannot be overriden
 226         ctx ->chunks[MemPlugin] = &ctx ->DefaultMemoryManager;
 227     }
 228 }
 229 
 230 // Auxiliary to fill memory management functions from plugin (or context 0 defaults)
 231 void _cmsInstallAllocFunctions(cmsPluginMemHandler* Plugin, _cmsMemPluginChunkType* ptr)
 232 {
 233     if (Plugin == NULL) {
 234 
 235         memcpy(ptr, &_cmsMemPluginChunk, sizeof(_cmsMemPluginChunk));
 236     }
 237     else {
 238 
 239         ptr ->MallocPtr  = Plugin -> MallocPtr;
 240         ptr ->FreePtr    = Plugin -> FreePtr;
 241         ptr ->ReallocPtr = Plugin -> ReallocPtr;
 242 
 243         // Make sure we revert to defaults
 244         ptr ->MallocZeroPtr= _cmsMallocZeroDefaultFn;
 245         ptr ->CallocPtr    = _cmsCallocDefaultFn;
 246         ptr ->DupPtr       = _cmsDupDefaultFn;
 247 
 248         if (Plugin ->MallocZeroPtr != NULL) ptr ->MallocZeroPtr = Plugin -> MallocZeroPtr;
 249         if (Plugin ->CallocPtr != NULL)     ptr ->CallocPtr     = Plugin -> CallocPtr;
 250         if (Plugin ->DupPtr != NULL)        ptr ->DupPtr        = Plugin -> DupPtr;


 442 {
 443     void *NewPtr;
 444 
 445     // Dup of null pointer is also NULL
 446     if (ptr == NULL)
 447         return NULL;
 448 
 449     NewPtr = _cmsSubAlloc(s, size);
 450 
 451     if (ptr != NULL && NewPtr != NULL) {
 452         memcpy(NewPtr, ptr, size);
 453     }
 454 
 455     return NewPtr;
 456 }
 457 
 458 
 459 
 460 // Error logging ******************************************************************
 461 
 462 // There is no error handling at all. When a function fails, it returns proper value.
 463 // For example, all create functions does return NULL on failure. Other return FALSE
 464 // It may be interesting, for the developer, to know why the function is failing.
 465 // for that reason, lcms2 does offer a logging function. This function does recive
 466 // a ENGLISH string with some clues on what is going wrong. You can show this
 467 // info to the end user, or just create some sort of log.
 468 // The logging function should NOT terminate the program, as this obviously can leave
 469 // resources. It is the programmer's responsibility to check each function return code
 470 // to make sure it didn't fail.
 471 
 472 // Error messages are limited to MAX_ERROR_MESSAGE_LEN
 473 
 474 #define MAX_ERROR_MESSAGE_LEN   1024
 475 
 476 // ---------------------------------------------------------------------------------------------------------
 477 
 478 // This is our default log error
 479 static void DefaultLogErrorHandlerFunction(cmsContext ContextID, cmsUInt32Number ErrorCode, const char *Text);
 480 
 481 // Context0 storage, which is global
 482 _cmsLogErrorChunkType _cmsLogErrorChunk = { DefaultLogErrorHandlerFunction };
 483 
 484 // Allocates and inits error logger container for a given context. If src is NULL, only initializes the value
 485 // to the default. Otherwise, it duplicates the value. The interface is standard across all context clients
 486 void _cmsAllocLogErrorChunk(struct _cmsContext_struct* ctx,
 487                             const struct _cmsContext_struct* src)
 488 {
 489     static _cmsLogErrorChunkType LogErrorChunk = { DefaultLogErrorHandlerFunction };


< prev index next >