static
void
-malloc_init() {
+malloc_init(void) {
int i;
for(i=0; i<MAXMAL; i++) malloc_pointers[i].ptr = NULL;
malloc_need_init = 0;
void
-malloc_state() {
+malloc_state(void) {
int i, total = 0;
+ i_clear_error();
mm_log((0,"malloc_state()\n"));
bndcheck_all();
for(i=0; i<MAXMAL; i++) if (malloc_pointers[i].ptr != NULL) {
exit(3);
}
- if ( (buf = realloc(ptr-UNDRRNVAL, UNDRRNVAL+OVERRNVAL+newsize) == NULL) ) {
+ if ( (buf = realloc(((char *)ptr)-UNDRRNVAL, UNDRRNVAL+OVERRNVAL+newsize)) == NULL ) {
mm_log((1,"Unable to reallocate %i bytes at %p for %s (%i)\n", newsize, ptr, file, line));
exit(3);
}
bndcheck_all() {
int idx;
mm_log((1, "bndcheck_all()\n"));
-for(idx=0; idx<MAXMAL; idx++)
+ for(idx=0; idx<MAXMAL; idx++)
if (malloc_pointers[idx].ptr)
bndcheck(idx);
}
if (match != 1) {
mm_log((1, "myfree_file_line: INCONSISTENT REFCOUNT %d at %s (%i)\n", match, file, line));
+ fprintf(stderr, "myfree_file_line: INCONSISTENT REFCOUNT %d at %s (%i)\n", match, file, line);
+ exit(255);
}
- mm_log((1, "myfree_file_line: freeing address %p\n", pp-UNDRRNVAL));
+ mm_log((1, "myfree_file_line: freeing address %p (real %p)\n", pp, pp-UNDRRNVAL));
free(pp-UNDRRNVAL);
}
+/* memory pool implementation */
+
+void
+i_mempool_init(i_mempool *mp) {
+ mp->alloc = 10;
+ mp->used = 0;
+ mp->p = mymalloc(sizeof(void*)*mp->alloc);
+}
+
+void
+i_mempool_extend(i_mempool *mp) {
+ mp->p = myrealloc(mp->p, mp->alloc * 2);
+ mp->alloc *=2;
+}
+
+void *
+i_mempool_alloc(i_mempool *mp, size_t size) {
+ if (mp->used == mp->alloc) i_mempool_extend(mp);
+ mp->p[mp->used] = mymalloc(size);
+ mp->used++;
+ return mp->p[mp->used-1];
+}
+
+
+void
+i_mempool_destroy(i_mempool *mp) {
+ unsigned int i;
+ for(i=0; i<mp->used; i++) myfree(mp->p[i]);
+ myfree(mp->p);
+}
+/* Should these really be here? */
#undef min
#undef max
if (a>b) return a; else return b;
}
-int
-myread(int fd,void *buf,int len) {
- unsigned char* bufc;
- int bc,rc;
- bufc = (unsigned char*)buf;
- bc=0;
- while( ((rc=read(fd,bufc+bc,len-bc))>0 ) && (bc!=len) ) bc+=rc;
- if ( rc < 0 ) return rc;
- else return bc;
-}
-
-int
-mywrite(int fd,void *buf,int len) {
- unsigned char* bufc;
- int bc,rc;
- bufc=(unsigned char*)buf;
- bc=0;
- while(((rc=write(fd,bufc+bc,len-bc))>0) && (bc!=len)) bc+=rc;
- if (rc<0) return rc;
- else return bc;
-}
-
-void
-interleave(unsigned char *inbuffer,unsigned char *outbuffer,int rowsize,int channels) {
- int ch,ind,i;
- i=0;
- if ( inbuffer==outbuffer ) return; /* Check if data is already in interleaved format */
- for( ind=0; ind<rowsize; ind++) for (ch=0; ch<channels; ch++) outbuffer[i++] = inbuffer[rowsize*ch+ind];
-}
-
-