2 * Copyright (C) 1994, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.1 1994-09-26 10:16:54 adam
8 * First version of dfa module in alex. This version uses yacc to parse
9 * regular expressions. This should be hand-made instead.
30 void *imalloc (size_t size)
33 size_t words = (4*sizeof(unsigned) -1 + size)/sizeof(unsigned);
34 char *p = (char *)malloc( words*sizeof(unsigned) );
36 log (LOG_FATAL, "No memory: imalloc(%u); c/f %d/%d; %ld/%ld",
37 size, alloc_calls, free_calls, alloc, max_alloc );
38 *((unsigned *)p) = size;
39 ((unsigned *)p)[1] = MAG1;
40 p += sizeof(unsigned)*2;
41 size[(unsigned char *) p] = MAG2;
42 size[(unsigned char *) p+1] = MAG3;
43 if( (alloc+=size) > max_alloc )
48 void *p = (void *)malloc( size );
50 log (LOG_FATAL, "Out of memory (imalloc)" );
55 void *icalloc (size_t size)
58 unsigned words = (4*sizeof(unsigned) -1 + size)/sizeof(unsigned);
59 char *p = (char *) calloc( words*sizeof(unsigned), 1 );
61 log (LOG_FATAL, "No memory: icalloc(%u); c/f %d/%d; %ld/%ld",
62 size, alloc_calls, free_calls, alloc, max_alloc );
63 ((unsigned *)p)[0] = size;
64 ((unsigned *)p)[1] = MAG1;
65 p += sizeof(unsigned)*2;
66 size[(unsigned char *) p] = MAG2;
67 size[(unsigned char *) p+1] = MAG3;
68 if( (alloc+=size) > max_alloc )
73 void p = (void) calloc( size, 1 );
75 log (LOG_FATAL, "Out of memory (icalloc)" );
87 size = (-2)[(unsigned *) p];
88 if( (-1)[(unsigned *) p] != MAG1 )
89 log (LOG_FATAL,"Internal: ifree(%u) magic 1 corrupted", size );
90 if( size[(unsigned char *) p] != MAG2 )
91 log (LOG_FATAL,"Internal: ifree(%u) magic 2 corrupted", size );
92 if( (size+1)[(unsigned char *) p] != MAG3 )
93 log (LOG_FATAL,"Internal: ifree(%u) magic 3 corrupted", size );
96 log (LOG_FATAL,"Internal: ifree(%u) negative alloc.", size );
97 free( (unsigned *) p-2 );
101 void i_free (void *p)
112 fprintf( stdout, "imalloc: calls malloc/free %d/%d, ",
113 alloc_calls, free_calls );
115 fprintf( stdout, "memory cur/max %ld/%ld : unreleased",
118 fprintf( stdout, "memory max %ld", max_alloc );
119 fputc( '\n', stdout );