2 * Copyright (C) 1994, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.3 1994-09-27 16:31:19 adam
8 * First version of grepper: grep with error correction.
10 * Revision 1.2 1994/09/26 16:30:56 adam
11 * Minor changes. imalloc uses xmalloc now.
13 * Revision 1.1 1994/09/26 10:16:54 adam
14 * First version of dfa module in alex. This version uses yacc to parse
15 * regular expressions. This should be hand-made instead.
36 void *imalloc (size_t size)
39 size_t words = (4*sizeof(unsigned) -1 + size)/sizeof(unsigned);
40 char *p = (char *)xmalloc( words*sizeof(unsigned) );
42 log (LOG_FATAL, "No memory: imalloc(%u); c/f %d/%d; %ld/%ld",
43 size, alloc_calls, free_calls, alloc, max_alloc );
44 *((unsigned *)p) = size;
45 ((unsigned *)p)[1] = MAG1;
46 p += sizeof(unsigned)*2;
47 size[(unsigned char *) p] = MAG2;
48 size[(unsigned char *) p+1] = MAG3;
49 if( (alloc+=size) > max_alloc )
54 void *p = (void *)xmalloc( size );
56 log (LOG_FATAL, "Out of memory (imalloc)" );
61 void *icalloc (size_t size)
64 unsigned words = (4*sizeof(unsigned) -1 + size)/sizeof(unsigned);
65 char *p = (char *) xcalloc( words*sizeof(unsigned), 1 );
67 log (LOG_FATAL, "No memory: icalloc(%u); c/f %d/%d; %ld/%ld",
68 size, alloc_calls, free_calls, alloc, max_alloc );
69 ((unsigned *)p)[0] = size;
70 ((unsigned *)p)[1] = MAG1;
71 p += sizeof(unsigned)*2;
72 size[(unsigned char *) p] = MAG2;
73 size[(unsigned char *) p+1] = MAG3;
74 if( (alloc+=size) > max_alloc )
79 void *p = (void) xcalloc( size, 1 );
81 log (LOG_FATAL, "Out of memory (icalloc)" );
93 size = (-2)[(unsigned *) p];
94 if( (-1)[(unsigned *) p] != MAG1 )
95 log (LOG_FATAL,"Internal: ifree(%u) magic 1 corrupted", size );
96 if( size[(unsigned char *) p] != MAG2 )
97 log (LOG_FATAL,"Internal: ifree(%u) magic 2 corrupted", size );
98 if( (size+1)[(unsigned char *) p] != MAG3 )
99 log (LOG_FATAL,"Internal: ifree(%u) magic 3 corrupted", size );
102 log (LOG_FATAL,"Internal: ifree(%u) negative alloc.", size );
103 xfree( (unsigned *) p-2 );
107 void i_free (void *p)
118 fprintf( stdout, "imalloc: calls malloc/free %d/%d, ",
119 alloc_calls, free_calls );
121 fprintf( stdout, "memory cur/max %ld/%ld : unreleased",
124 fprintf( stdout, "memory max %ld", max_alloc );
125 fputc( '\n', stdout );