]> git.imager.perl.org - imager.git/blobdiff - iolayer.c
Fixed i_transform2() so malloc(0) doesn't happen. Also corrected pod errors and
[imager.git] / iolayer.c
index f3ae78e093c09ee2dacfd8fc22a444e0366a8163..7089ffeccae5b09de5fac56b1972887ac9480660 100644 (file)
--- a/iolayer.c
+++ b/iolayer.c
@@ -52,7 +52,7 @@ objects for Imager.  The typical usage pattern for data sources is:
 
 Some of these functions are internal.
 
-=over 4
+=over
 
 =cut
 */
@@ -100,7 +100,7 @@ realseek_read(io_glue *ig, void *buf, size_t count) {
   size_t        bc = 0;
   char       *cbuf = buf;
 
-  IOL_DEB( printf("realseek_read: fd = %d, ier->cpos = %ld, buf = 0x%p, count = %d\n", fd, (long) ier->cpos, buf, count) );
+  IOL_DEB( printf("realseek_read: fd = %d, ier->cpos = %ld, buf = %p, count = %d\n", fd, (long) ier->cpos, buf, count) );
   /* Is this a good idea? Would it be better to handle differently? skip handling? */
   while( count!=bc && (rc = ig->source.cb.readcb(fd,cbuf+bc,count-bc))>0 ) bc+=rc;
   
@@ -131,7 +131,7 @@ realseek_write(io_glue *ig, const void *buf, size_t count) {
   size_t        bc = 0;
   char       *cbuf = (char*)buf; 
   
-  IOL_DEB( printf("realseek_write: fd = %d, ier->cpos = %ld, buf = 0x%p, count = %d\n", fd, (long) ier->cpos, buf, count) );
+  IOL_DEB( printf("realseek_write: fd = %d, ier->cpos = %ld, buf = %p, count = %d\n", fd, (long) ier->cpos, buf, count) );
   /* Is this a good idea? Would it be better to handle differently? skip handling? */
 
   while( count!=bc && (rc = ig->source.cb.writecb(fd,cbuf+bc,count-bc))>0 ) bc+=rc;
@@ -179,7 +179,7 @@ realseek_seek(io_glue *ig, off_t offset, int whence) {
   /*  io_ex_rseek *ier = ig->exdata; Needed later */
   int fd           = (int)ig->source.cb.p;
   int rc;
-  IOL_DEB( printf("realseek_seek(ig 0x%p, offset %ld, whence %d)\n", ig, (long) offset, whence) );
+  IOL_DEB( printf("realseek_seek(ig %p, offset %ld, whence %d)\n", ig, (long) offset, whence) );
   rc = lseek(fd, offset, whence);
 
   IOL_DEB( printf("realseek_seek: rc %ld\n", (long) rc) );
@@ -203,7 +203,7 @@ realseek_seek(io_glue *ig, off_t offset, int whence) {
 
 static
 io_blink*
-io_blink_new() {
+io_blink_new(void) {
   io_blink *ib;
 
   mm_log((1, "io_blink_new()\n"));
@@ -246,6 +246,28 @@ io_bchain_advance(io_ex_bchain *ieb) {
 }
 
 
+
+/*
+=item io_bchain_destroy()
+
+frees all resources used by a buffer chain.
+
+=cut
+*/
+
+void
+io_destroy_bufchain(io_ex_bchain *ieb) {
+  io_blink *cp = ieb->head;
+  while(cp) {
+    io_blink *t = cp->next;
+    free(cp);
+    cp = t;
+  }
+}
+
+
+
+
 /*
 
 static
@@ -376,7 +398,6 @@ bufchain_read(io_glue *ig, void *buf, size_t count) {
   size_t         sk;
 
   mm_log((1, "bufchain_read(ig %p, buf %p, count %ld)\n", ig, buf, count));
-  IOL_DEB( printf("bufchain_read: fd = %d, ier->cpos = %ld, buf = 0x%p, count = %d\n", fd, (long) ier->cpos, buf, count) );
 
   while( scount ) {
     int clen = (ieb->cp == ieb->tail) ? ieb->tfill : ieb->cp->len;
@@ -424,9 +445,9 @@ bufchain_write(io_glue *ig, const void *buf, size_t count) {
   size_t         ocount = count;
   size_t         sk;
 
-  mm_log((1, "bufchain_write: ig = %p, buf = 0x%p, count = %d\n", ig, buf, count));
+  mm_log((1, "bufchain_write: ig = %p, buf = %p, count = %d\n", ig, buf, count));
 
-  IOL_DEB( printf("bufchain_write: ig = %p, ieb->cpos = %ld, buf = 0x%p, count = %d\n", ig, (long) ieb->cpos, buf, count) );
+  IOL_DEB( printf("bufchain_write: ig = %p, ieb->cpos = %ld, buf = %p, count = %d\n", ig, (long) ieb->cpos, buf, count) );
   
   while(count) {
     mm_log((2, "bufchain_write: - looping - count = %d\n", count));
@@ -470,7 +491,7 @@ static
 void
 bufchain_close(io_glue *ig) {
   mm_log((1, "bufchain_close(ig %p)\n",ig));
-  IOL_DEB( printf("bufchain_close(ig 0x%p)\n", ig) );
+  IOL_DEB( printf("bufchain_close(ig %p)\n", ig) );
   /* FIXME: Commit a seek point here */
   
 }
@@ -674,7 +695,7 @@ void
 io_glue_commit_types(io_glue *ig) {
   io_type      inn = ig->source.type;
   
-  mm_log((1, "io_glue_commit_types(ig 0x%p)\n", ig));
+  mm_log((1, "io_glue_commit_types(ig %p)\n", ig));
   mm_log((1, "io_glue_commit_types: source type %d (%s)\n", inn, io_type_names[inn]));
   
   switch (inn) {
@@ -687,7 +708,7 @@ io_glue_commit_types(io_glue *ig) {
       ieb->cpos   = 0;
       ieb->gpos   = 0;
       ieb->tfill  = 0;
-      
+
       ieb->head   = io_blink_new();
       ieb->cp     = ieb->head;
       ieb->tail   = ieb->head;
@@ -761,6 +782,12 @@ io_new_bufchain() {
 }
 
 
+
+
+
+
+
+
 /*
 =item io_new_fd(fd)
 
@@ -776,6 +803,7 @@ data from the io_glue callbacks hasn't been done yet.
 io_glue *
 io_new_fd(int fd) {
   io_glue *ig = mymalloc(sizeof(io_glue));
+  memset(ig, 0, sizeof(*ig));
 #ifdef _MSC_VER
   io_obj_setp_cb(&ig->source, (void*)fd, _read, _write, _lseek);
 #else
@@ -841,6 +869,38 @@ Might leave us with a dangling pointer issue on some buffers.
 
 void
 io_glue_DESTROY(io_glue *ig) {
-  free(ig);
-  /* FIXME: Handle extradata and such */
+  io_type      inn = ig->source.type;
+  mm_log((1, "io_glue_DESTROY(ig %p)\n", ig));
+  
+  switch (inn) {
+  case BUFCHAIN:
+    {
+      io_ex_bchain *ieb = ig->exdata;
+      io_destroy_bufchain(ieb);
+    }
+    break;
+  case CBSEEK:
+  default:
+    {
+      io_ex_rseek *ier = ig->exdata;
+      myfree(ier);
+    }
+
+  }
+  myfree(ig);
 }
+
+
+/*
+=back
+
+=head1 AUTHOR
+
+Arnar M. Hrafnkelsson <addi@umich.edu>
+
+=head1 SEE ALSO
+
+Imager(3)
+
+=cut
+*/