1 /* alloc.c -- Default memory allocation routines.
3 (c) 1998-2006 (W3C) MIT, ERCIM, Keio University
4 See tidy.h for the copyright notice.
11 static TidyMalloc g_malloc = NULL;
12 static TidyRealloc g_realloc = NULL;
13 static TidyFree g_free = NULL;
14 static TidyPanic g_panic = NULL;
16 Bool TIDY_CALL tidySetMallocCall( TidyMalloc fmalloc )
21 Bool TIDY_CALL tidySetReallocCall( TidyRealloc frealloc )
26 Bool TIDY_CALL tidySetFreeCall( TidyFree ffree )
31 Bool TIDY_CALL tidySetPanicCall( TidyPanic fpanic )
37 static void TIDY_CALL defaultPanic( TidyAllocator* ARG_UNUSED(allocator), ctmbstr msg )
43 /* 2 signifies a serious error */
44 fprintf( stderr, "Fatal error: %s\n", msg );
52 static void* TIDY_CALL defaultAlloc( TidyAllocator* allocator, size_t size )
54 void *p = ( g_malloc ? g_malloc(size) : malloc(size) );
56 defaultPanic( allocator,"Out of memory!");
60 static void* TIDY_CALL defaultRealloc( TidyAllocator* allocator, void* mem, size_t newsize )
64 return defaultAlloc( allocator, newsize );
66 p = ( g_realloc ? g_realloc(mem, newsize) : realloc(mem, newsize) );
68 defaultPanic( allocator, "Out of memory!");
72 static void TIDY_CALL defaultFree( TidyAllocator* ARG_UNUSED(allocator), void* mem )
83 static const TidyAllocatorVtbl defaultVtbl = {
90 TidyAllocator TY_(g_default_allocator) = {
97 * indent-tabs-mode: nil
99 * eval: (c-set-offset 'substatement-open 0)