]> git.imager.perl.org - imager.git/blobdiff - io.c
modify the Freetype2 font code to pick it's own encoding rather than
[imager.git] / io.c
diff --git a/io.c b/io.c
index 2c65958ca9dbe050ad5921bfc969ea74039b15f7..1936ee8a227b5f174fa8c60c23f00477aaea3675 100644 (file)
--- a/io.c
+++ b/io.c
@@ -37,7 +37,7 @@ malloc_entry malloc_pointers[MAXMAL];
 
 static
 void
-malloc_init() {
+malloc_init(void) {
   int i;
   for(i=0; i<MAXMAL; i++) malloc_pointers[i].ptr = NULL;
   malloc_need_init = 0;
@@ -76,9 +76,10 @@ set_entry(int i, char *buf, size_t size, char *file, int line) {
 
 
 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) {
@@ -144,7 +145,7 @@ myrealloc_file_line(void *ptr, size_t newsize, char* file, int line) {
     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); 
   }
@@ -181,7 +182,7 @@ void
 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);
 }
@@ -205,9 +206,11 @@ myfree_file_line(void *p, char *file, int line) {
   
   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);
 }
@@ -257,9 +260,40 @@ myrealloc(void *block, size_t size) {
 
 
 
+/* 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
@@ -274,34 +308,3 @@ max(int a,int b) {
   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]; 
-}
-
-