
#undef calloc
#undef malloc
#undef free

extern void *calloc(size_t , size_t );
extern void free(void * );
extern void *malloc(size_t );


void * wimp_calloc(size_t no,size_t sz)
{
unsigned int i=no*sz;
int j;
char * tmp;
if (i<=0 || heap_ptr >heap_top) return(0);
tmp=alloc[heap_ptr]=(char *)calloc(no*sz,1);
if (tmp==0) return(0);
j=heap_ptr++;
return((void *)alloc[j]);
}


void * wimp_malloc(size_t no)
{
unsigned i=no;
int j;
char * tmp;
if (i<=0 || heap_ptr > heap_top) return(0);
tmp=alloc[heap_ptr]=(char *)malloc(no);
if (tmp==0) return(0);
j=heap_ptr++;
return((void *)alloc[j]);
}

void wimp_free(void * ptr)
{
 int i=heap_ptr,j; 
 while ( alloc[i] != (char*)ptr && i >=heap_bottom ) i--;
 if (i <heap_bottom ) {
   wprintf("Try to free an illegal pointer!!! \n");
 return; }
 free(alloc[i]);
 for (j=i;j<heap_ptr;j++) alloc[j]=alloc[j+1];
 heap_ptr--;
}
