2 * Copyright (C) 1994, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.4 1995-09-04 12:33:26 adam
8 * Various cleanup. YAZ util used instead.
10 * Revision 1.3 1994/09/27 16:31:19 adam
11 * First version of grepper: grep with error correction.
13 * Revision 1.2 1994/09/26 16:30:56 adam
14 * Minor changes. imalloc uses xmalloc now.
16 * Revision 1.1 1994/09/26 10:16:54 adam
17 * First version of dfa module in alex. This version uses yacc to parse
18 * regular expressions. This should be hand-made instead.
39 void *imalloc (size_t size)
42 size_t words = (4*sizeof(unsigned) -1 + size)/sizeof(unsigned);
43 char *p = (char *)xmalloc( words*sizeof(unsigned) );
45 logf (LOG_FATAL, "No memory: imalloc(%u); c/f %d/%d; %ld/%ld",
46 size, alloc_calls, free_calls, alloc, max_alloc );
47 *((unsigned *)p) = size;
48 ((unsigned *)p)[1] = MAG1;
49 p += sizeof(unsigned)*2;
50 size[(unsigned char *) p] = MAG2;
51 size[(unsigned char *) p+1] = MAG3;
52 if( (alloc+=size) > max_alloc )
57 void *p = (void *)xmalloc( size );
59 logf (LOG_FATAL, "Out of memory (imalloc)" );
64 void *icalloc (size_t size)
67 unsigned words = (4*sizeof(unsigned) -1 + size)/sizeof(unsigned);
68 char *p = (char *) xcalloc( words*sizeof(unsigned), 1 );
70 logf (LOG_FATAL, "No memory: icalloc(%u); c/f %d/%d; %ld/%ld",
71 size, alloc_calls, free_calls, alloc, max_alloc );
72 ((unsigned *)p)[0] = size;
73 ((unsigned *)p)[1] = MAG1;
74 p += sizeof(unsigned)*2;
75 size[(unsigned char *) p] = MAG2;
76 size[(unsigned char *) p+1] = MAG3;
77 if( (alloc+=size) > max_alloc )
82 void *p = (void) xcalloc( size, 1 );
84 logf (LOG_FATAL, "Out of memory (icalloc)" );
96 size = (-2)[(unsigned *) p];
97 if( (-1)[(unsigned *) p] != MAG1 )
98 logf (LOG_FATAL,"Internal: ifree(%u) magic 1 corrupted", size );
99 if( size[(unsigned char *) p] != MAG2 )
100 logf (LOG_FATAL,"Internal: ifree(%u) magic 2 corrupted", size );
101 if( (size+1)[(unsigned char *) p] != MAG3 )
102 logf (LOG_FATAL,"Internal: ifree(%u) magic 3 corrupted", size );
105 logf (LOG_FATAL,"Internal: ifree(%u) negative alloc.", size );
106 xfree( (unsigned *) p-2 );
110 void i_free (void *p)
121 fprintf( stdout, "imalloc: calls malloc/free %d/%d, ",
122 alloc_calls, free_calls );
124 fprintf( stdout, "memory cur/max %ld/%ld : unreleased",
127 fprintf( stdout, "memory max %ld", max_alloc );
128 fputc( '\n', stdout );