2 * Copyright (C) 1994-1996, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.5 1996-05-14 11:33:41 adam
8 * MEMDEBUG turned off by default.
10 * Revision 1.4 1995/09/04 12:33:26 adam
11 * Various cleanup. YAZ util used instead.
13 * Revision 1.3 1994/09/27 16:31:19 adam
14 * First version of grepper: grep with error correction.
16 * Revision 1.2 1994/09/26 16:30:56 adam
17 * Minor changes. imalloc uses xmalloc now.
19 * Revision 1.1 1994/09/26 10:16:54 adam
20 * First version of dfa module in alex. This version uses yacc to parse
21 * regular expressions. This should be hand-made instead.
42 void *imalloc (size_t size)
45 size_t words = (4*sizeof(unsigned) -1 + size)/sizeof(unsigned);
46 char *p = (char *)xmalloc( words*sizeof(unsigned) );
48 logf (LOG_FATAL, "No memory: imalloc(%u); c/f %d/%d; %ld/%ld",
49 size, alloc_calls, free_calls, alloc, max_alloc );
50 *((unsigned *)p) = size;
51 ((unsigned *)p)[1] = MAG1;
52 p += sizeof(unsigned)*2;
53 size[(unsigned char *) p] = MAG2;
54 size[(unsigned char *) p+1] = MAG3;
55 if( (alloc+=size) > max_alloc )
60 void *p = (void *)xmalloc( size );
62 logf (LOG_FATAL, "Out of memory (imalloc)" );
67 void *icalloc (size_t size)
70 unsigned words = (4*sizeof(unsigned) -1 + size)/sizeof(unsigned);
71 char *p = (char *) xcalloc( words*sizeof(unsigned), 1 );
73 logf (LOG_FATAL, "No memory: icalloc(%u); c/f %d/%d; %ld/%ld",
74 size, alloc_calls, free_calls, alloc, max_alloc );
75 ((unsigned *)p)[0] = size;
76 ((unsigned *)p)[1] = MAG1;
77 p += sizeof(unsigned)*2;
78 size[(unsigned char *) p] = MAG2;
79 size[(unsigned char *) p+1] = MAG3;
80 if( (alloc+=size) > max_alloc )
85 void *p = (void *) xcalloc( size, 1 );
87 logf (LOG_FATAL, "Out of memory (icalloc)" );
99 size = (-2)[(unsigned *) p];
100 if( (-1)[(unsigned *) p] != MAG1 )
101 logf (LOG_FATAL,"Internal: ifree(%u) magic 1 corrupted", size );
102 if( size[(unsigned char *) p] != MAG2 )
103 logf (LOG_FATAL,"Internal: ifree(%u) magic 2 corrupted", size );
104 if( (size+1)[(unsigned char *) p] != MAG3 )
105 logf (LOG_FATAL,"Internal: ifree(%u) magic 3 corrupted", size );
108 logf (LOG_FATAL,"Internal: ifree(%u) negative alloc.", size );
109 xfree( (unsigned *) p-2 );
116 fprintf( stdout, "imalloc: calls malloc/free %d/%d, ",
117 alloc_calls, free_calls );
119 fprintf( stdout, "memory cur/max %ld/%ld : unreleased",
122 fprintf( stdout, "memory max %ld", max_alloc );
123 fputc( '\n', stdout );