]> granicus.if.org Git - php/commitdiff
No more (f)printf for errors and warnings instead use php_error_docref.
authorMarcus Boerger <helly@php.net>
Sun, 1 Dec 2002 11:43:54 +0000 (11:43 +0000)
committerMarcus Boerger <helly@php.net>
Sun, 1 Dec 2002 11:43:54 +0000 (11:43 +0000)
ext/gd/libgd/gd.c
ext/gd/libgd/gd.h
ext/gd/libgd/gd_arc_f_buggy.c
ext/gd/libgd/gd_gd2.c
ext/gd/libgd/gd_gif_in.c
ext/gd/libgd/gd_jpeg.c
ext/gd/libgd/gd_png.c
ext/gd/libgd/gd_ss.c
ext/gd/libgd/gd_wbmp.c
ext/gd/libgd/gdkanji.c
ext/gd/libgd/gdxpm.c

index 56eb5c89fb0a42a286f52c08f8718edbc5d94231..91d0b242c4ffac8110fde7fe09fe4140a6fd0128 100644 (file)
@@ -92,6 +92,28 @@ static int gdAlphaBlendColor(int b1, int b2, int a1, int a2);
 static int gdAlphaOverlayColor(int src, int dst, int max);
 static int gdImageGetTrueColorPixel(gdImagePtr im, int x, int y);
 
+void php_gd_error_ex(int type, const char *format, ...) 
+{
+       va_list args;
+       
+       TSRMLS_FETCH();
+       
+       va_start(args, format);
+       php_verror(NULL, "", type, format, args TSRMLS_CC);
+       va_end(args);
+}
+
+void php_gd_error(const char *format, ...)
+{
+       va_list args;
+       
+       TSRMLS_FETCH();
+       
+       va_start(args, format);
+       php_verror(NULL, "", E_WARNING, format, args TSRMLS_CC);
+       va_end(args);
+}
+
 gdImagePtr
 gdImageCreate (int sx, int sy)
 {
@@ -2780,7 +2802,7 @@ gdImageCreateFromXbm (FILE * fd)
        }
     }
   /* Shouldn't happen */
-  fprintf (stderr, "Error: bug in gdImageCreateFromXbm!\n");
+  php_gd_error("Error: bug in gdImageCreateFromXbm\n");
   return 0;
 fail:
   gdImageDestroy (im);
index 7d09d40949dbf03e411677eec286f839cbc72236..5031509c7135417ff3facf4064e1a8223d53bab1 100644 (file)
@@ -30,6 +30,11 @@ extern "C" {
 #include <stdio.h>
 #include "gd_io.h"
 
+void php_gd_error_ex(int type, const char *format, ...);
+
+void php_gd_error(const char *format, ...);
+
+
 /* The maximum number of palette entries in palette-based images.
        In the wonderful new world of gd 2.0, you can of course have
        many more colors when using truecolor mode. */
index 1e33b266083447d5ee1299d48c9768d6ba3c7c44..7b8f819079ad7b33bc898b009231251aced18ca4 100644 (file)
@@ -726,12 +726,12 @@ main (int argc, char *argv[])
   out = fopen ("test/arctest.png", "wb");
   if (!out)
     {
-      fprintf (stderr, "Can't create test/arctest.png\n");
+      php_gd_error("Can't create test/arctest.png\n");
       exit (1);
     }
   gdImagePng (im, out);
   fclose (out);
-  fprintf (stderr, "Test image written to test/arctest.png\n");
+  php_gd_error("Test image written to test/arctest.png\n");
   /* Destroy it */
   gdImageDestroy (im);
 
index 967c99e40253abb60ef95ba20fede4ee6217b319..eab50ad9df03d69667a9606a1427fa0695751092 100644 (file)
@@ -25,8 +25,8 @@
 
 /* Use this for commenting out debug-print statements. */
 /* Just use the first '#define' to allow all the prints... */
-/*#define GD2_DBG(s) (s) */
-#define GD2_DBG(s)
+#define GD2_DBG(s) (s) 
+//#define GD2_DBG(s)
 
 typedef struct
   {
@@ -53,7 +53,7 @@ _gd2GetHeader (gdIOCtxPtr in, int *sx, int *sy,
   int sidx;
   int nc;
 
-  GD2_DBG (printf ("Reading gd2 header info\n"));
+  GD2_DBG(php_gd_error("Reading gd2 header info\n"));
 
   for (i = 0; i < 4; i++)
     {
@@ -66,12 +66,12 @@ _gd2GetHeader (gdIOCtxPtr in, int *sx, int *sy,
     };
   id[4] = 0;
 
-  GD2_DBG (printf ("Got file code: %s\n", id));
+  GD2_DBG(php_gd_error("Got file code: %s\n", id));
 
   /* Equiv. of 'magick'.  */
   if (strcmp (id, GD2_ID) != 0)
     {
-      GD2_DBG (printf ("Not a valid gd2 file\n"));
+      GD2_DBG(php_gd_error("Not a valid gd2 file\n"));
       goto fail1;
     };
 
@@ -80,37 +80,37 @@ _gd2GetHeader (gdIOCtxPtr in, int *sx, int *sy,
     {
       goto fail1;
     };
-  GD2_DBG (printf ("Version: %d\n", *vers));
+  GD2_DBG(php_gd_error("Version: %d\n", *vers));
 
   if ((*vers != 1) && (*vers != 2))
     {
-      GD2_DBG (printf ("Bad version: %d\n", *vers));
+      GD2_DBG(php_gd_error("Bad version: %d\n", *vers));
       goto fail1;
     };
 
   /* Image Size */
   if (!gdGetWord (sx, in))
     {
-      GD2_DBG (printf ("Could not get x-size\n"));
+      GD2_DBG(php_gd_error("Could not get x-size\n"));
       goto fail1;
     }
   if (!gdGetWord (sy, in))
     {
-      GD2_DBG (printf ("Could not get y-size\n"));
+      GD2_DBG(php_gd_error("Could not get y-size\n"));
       goto fail1;
     }
-  GD2_DBG (printf ("Image is %dx%d\n", *sx, *sy));
+  GD2_DBG(php_gd_error("Image is %dx%d\n", *sx, *sy));
 
   /* Chunk Size (pixels, not bytes!) */
   if (gdGetWord (cs, in) != 1)
     {
       goto fail1;
     };
-  GD2_DBG (printf ("ChunkSize: %d\n", *cs));
+  GD2_DBG(php_gd_error("ChunkSize: %d\n", *cs));
 
   if ((*cs < GD2_CHUNKSIZE_MIN) || (*cs > GD2_CHUNKSIZE_MAX))
     {
-      GD2_DBG (printf ("Bad chunk size: %d\n", *cs));
+      GD2_DBG(php_gd_error("Bad chunk size: %d\n", *cs));
       goto fail1;
     };
 
@@ -119,11 +119,11 @@ _gd2GetHeader (gdIOCtxPtr in, int *sx, int *sy,
     {
       goto fail1;
     };
-  GD2_DBG (printf ("Format: %d\n", *fmt));
+  GD2_DBG(php_gd_error("Format: %d\n", *fmt));
 
   if ((*fmt != GD2_FMT_RAW) && (*fmt != GD2_FMT_COMPRESSED))
     {
-      GD2_DBG (printf ("Bad data format: %d\n", *fmt));
+      GD2_DBG(php_gd_error("Bad data format: %d\n", *fmt));
       goto fail1;
     };
 
@@ -133,19 +133,19 @@ _gd2GetHeader (gdIOCtxPtr in, int *sx, int *sy,
     {
       goto fail1;
     };
-  GD2_DBG (printf ("%d Chunks Wide\n", *ncx));
+  GD2_DBG(php_gd_error("%d Chunks Wide\n", *ncx));
 
   /* # of chunks high */
   if (gdGetWord (ncy, in) != 1)
     {
       goto fail1;
     };
-  GD2_DBG (printf ("%d Chunks vertically\n", *ncy));
+  GD2_DBG(php_gd_error("%d Chunks vertically\n", *ncy));
 
   if ((*fmt) == GD2_FMT_COMPRESSED)
     {
       nc = (*ncx) * (*ncy);
-      GD2_DBG (printf ("Reading %d chunk index entries\n", nc));
+      GD2_DBG(php_gd_error("Reading %d chunk index entries\n", nc));
       sidx = sizeof (t_chunk_info) * nc;
       cidx = gdCalloc (sidx, 1);
       for (i = 0; i < nc; i++)
@@ -162,7 +162,7 @@ _gd2GetHeader (gdIOCtxPtr in, int *sx, int *sy,
       *chunkIdx = cidx;
     };
 
-  GD2_DBG (printf ("gd2 header complete\n"));
+  GD2_DBG(php_gd_error("gd2 header complete\n"));
 
   return 1;
 
@@ -180,23 +180,23 @@ _gd2CreateFromFile (gdIOCtxPtr in, int *sx, int *sy,
 
   if (_gd2GetHeader (in, sx, sy, cs, vers, fmt, ncx, ncy, cidx) != 1)
     {
-      GD2_DBG (printf ("Bad GD2 header\n"));
+      GD2_DBG(php_gd_error("Bad GD2 header\n"));
       goto fail1;
     }
 
   im = gdImageCreate (*sx, *sy);
   if (im == NULL)
     {
-      GD2_DBG (printf ("Could not create gdImage\n"));
+      GD2_DBG(php_gd_error("Could not create gdImage\n"));
       goto fail1;
     };
 
   if (!_gdGetColors (in, im, (*vers) == 2))
     {
-      GD2_DBG (printf ("Could not read color palette\n"));
+      GD2_DBG(php_gd_error("Could not read color palette\n"));
       goto fail2;
     }
-  GD2_DBG (printf ("Image palette completed: %d colours\n", im->colorsTotal));
+  GD2_DBG(php_gd_error("Image palette completed: %d colours\n", im->colorsTotal));
 
   return im;
 
@@ -217,29 +217,29 @@ _gd2ReadChunk (int offset, char *compBuf, int compSize, char *chunkBuf, uLongf *
 
   if (gdTell (in) != offset)
     {
-      GD2_DBG (printf ("Positioning in file to %d\n", offset));
+      GD2_DBG(php_gd_error("Positioning in file to %d\n", offset));
       gdSeek (in, offset);
     }
   else
     {
-      GD2_DBG (printf ("Already Positioned in file to %d\n", offset));
+      GD2_DBG(php_gd_error("Already Positioned in file to %d\n", offset));
     };
 
   /* Read and uncompress an entire chunk. */
-  GD2_DBG (printf ("Reading file\n"));
+  GD2_DBG(php_gd_error("Reading file\n"));
   if (gdGetBuf (compBuf, compSize, in) != compSize)
     {
       return FALSE;
     };
-  GD2_DBG (printf ("Got %d bytes. Uncompressing into buffer of %d bytes\n", compSize, *chunkLen));
+  GD2_DBG(php_gd_error("Got %d bytes. Uncompressing into buffer of %d bytes\n", compSize, (int)*chunkLen));
   zerr = uncompress ((unsigned char *) chunkBuf, chunkLen,
                     (unsigned char *) compBuf, compSize);
   if (zerr != Z_OK)
     {
-      GD2_DBG (printf ("Error %d from uncompress\n", zerr));
+      GD2_DBG(php_gd_error("Error %d from uncompress\n", zerr));
       return FALSE;
     };
-  GD2_DBG (printf ("Got chunk\n"));
+  GD2_DBG(php_gd_error("Got chunk\n"));
   return TRUE;
 }
 
@@ -303,7 +303,7 @@ gdImageCreateFromGd2Ctx (gdIOCtxPtr in)
       chunkMax = cs * bytesPerPixel * cs;
       chunkBuf = gdCalloc (chunkMax, 1);
       compBuf = gdCalloc (compMax, 1);
-      GD2_DBG (printf ("Largest compressed chunk is %d bytes\n", compMax));
+      GD2_DBG(php_gd_error("Largest compressed chunk is %d bytes\n", compMax));
     };
 
 /*      if ( (ncx != sx / cs) || (ncy != sy / cs)) { */
@@ -323,7 +323,7 @@ gdImageCreateFromGd2Ctx (gdIOCtxPtr in)
              yhi = im->sy;
            };
 
-         GD2_DBG (printf ("Processing Chunk %d (%d, %d), y from %d to %d\n", chunkNum, cx, cy, ylo, yhi));
+         GD2_DBG(php_gd_error("Processing Chunk %d (%d, %d), y from %d to %d\n", chunkNum, cx, cy, ylo, yhi));
 
          if (fmt == GD2_FMT_COMPRESSED)
            {
@@ -335,7 +335,7 @@ gdImageCreateFromGd2Ctx (gdIOCtxPtr in)
                                  chunkIdx[chunkNum].size,
                                  chunkBuf, &chunkLen, in))
                {
-                 GD2_DBG (printf ("Error reading comproessed chunk\n"));
+                 GD2_DBG(php_gd_error("Error reading comproessed chunk\n"));
                  goto fail2;
                };
 
@@ -351,7 +351,7 @@ gdImageCreateFromGd2Ctx (gdIOCtxPtr in)
                {
                  xhi = im->sx;
                };
-             /*GD2_DBG(printf("y=%d: ",y)); */
+             /*GD2_DBG(php_gd_error("y=%d: ",y)); */
              if (fmt == GD2_FMT_RAW)
                {
                  for (x = xlo; x < xhi; x++)
@@ -361,7 +361,7 @@ gdImageCreateFromGd2Ctx (gdIOCtxPtr in)
                        {
                          if (!gdGetInt (&im->tpixels[y][x], in))
                            {
-                             /*printf("EOF while reading\n"); */
+                             /*php_gd_error("EOF while reading\n"); */
                              /*gdImageDestroy(im); */
                              /*return 0; */
                              im->tpixels[y][x] = 0;
@@ -372,7 +372,7 @@ gdImageCreateFromGd2Ctx (gdIOCtxPtr in)
                          int ch;
                          if (!gdGetByte (&ch, in))
                            {
-                             /*printf("EOF while reading\n"); */
+                             /*php_gd_error("EOF while reading\n"); */
                              /*gdImageDestroy(im); */
                              /*return 0; */
                              ch = 0;
@@ -401,19 +401,19 @@ gdImageCreateFromGd2Ctx (gdIOCtxPtr in)
                        }
                    };
                };
-             /*GD2_DBG(printf("\n")); */
+             /*GD2_DBG(php_gd_error("\n")); */
            };
          chunkNum++;
        };
     };
 
-  GD2_DBG (printf ("Freeing memory\n"));
+  GD2_DBG(php_gd_error("Freeing memory\n"));
 
   gdFree (chunkBuf);
   gdFree (compBuf);
   gdFree (chunkIdx);
 
-  GD2_DBG (printf ("Done\n"));
+  GD2_DBG(php_gd_error("Done\n"));
 
   return im;
 
@@ -469,7 +469,7 @@ gdImageCreateFromGd2PartCtx (gdIOCtx * in, int srcx, int srcy, int w, int h)
       goto fail1;
     }
 
-  GD2_DBG (printf ("File size is %dx%d\n", fsx, fsy));
+  GD2_DBG(php_gd_error("File size is %dx%d\n", fsx, fsy));
 
   /* This is the difference - make a file based on size of chunks. */
   im = gdImageCreate (w, h);
@@ -482,7 +482,7 @@ gdImageCreateFromGd2PartCtx (gdIOCtx * in, int srcx, int srcy, int w, int h)
     {
       goto fail2;
     }
-  GD2_DBG (printf ("Image palette completed: %d colours\n", im->colorsTotal));
+  GD2_DBG(php_gd_error("Image palette completed: %d colours\n", im->colorsTotal));
 
   /* Process the header info */
   nc = ncx * ncy;
@@ -543,7 +543,7 @@ gdImageCreateFromGd2PartCtx (gdIOCtx * in, int srcx, int srcy, int w, int h)
 
   /* Remember file position of image data. */
   dstart = gdTell (in);
-  GD2_DBG (printf ("Data starts at %d\n", dstart));
+  GD2_DBG(php_gd_error("Data starts at %d\n", dstart));
 
   /* Loop through the chunks. */
   for (cy = scy; (cy <= ecy); cy++)
@@ -566,11 +566,11 @@ gdImageCreateFromGd2PartCtx (gdIOCtx * in, int srcx, int srcy, int w, int h)
              xhi = fsx;
            };
 
-         GD2_DBG (printf ("Processing Chunk (%d, %d), from %d to %d\n", cx, cy, ylo, yhi));
+         GD2_DBG(php_gd_error("Processing Chunk (%d, %d), from %d to %d\n", cx, cy, ylo, yhi));
 
          if (fmt == GD2_FMT_RAW)
            {
-             GD2_DBG (printf ("Using raw format data\n"));
+             GD2_DBG(php_gd_error("Using raw format data\n"));
              if (im->trueColor)
                {
                  dpos = (cy * (cs * fsx) + cx * cs * (yhi - ylo) * 4) + dstart;
@@ -582,10 +582,10 @@ gdImageCreateFromGd2PartCtx (gdIOCtx * in, int srcx, int srcy, int w, int h)
 
              if (gdSeek (in, dpos) != 0)
                {
-                 printf ("Error from seek: %d\n", errno);
+                 php_gd_error_ex(E_WARNING, "Error from seek: %d\n", errno);
                  goto fail2;
                };
-             GD2_DBG (printf ("Reading (%d, %d) from position %d\n", cx, cy, dpos - dstart));
+             GD2_DBG(php_gd_error("Reading (%d, %d) from position %d\n", cx, cy, dpos - dstart));
            }
          else
            {
@@ -597,14 +597,14 @@ gdImageCreateFromGd2PartCtx (gdIOCtx * in, int srcx, int srcy, int w, int h)
                                  chunkIdx[chunkNum].size,
                                  chunkBuf, &chunkLen, in))
                {
-                 printf ("Error reading comproessed chunk\n");
+                 php_gd_error("Error reading comproessed chunk\n");
                  goto fail2;
                };
              chunkPos = 0;
-             GD2_DBG (printf ("Reading (%d, %d) from chunk %d\n", cx, cy, chunkNum));
+             GD2_DBG(php_gd_error("Reading (%d, %d) from chunk %d\n", cx, cy, chunkNum));
            };
 
-         GD2_DBG (printf ("   into (%d, %d) - (%d, %d)\n", xlo, ylo, xhi, yhi));
+         GD2_DBG(php_gd_error("   into (%d, %d) - (%d, %d)\n", xlo, ylo, xhi, yhi));
          for (y = ylo; (y < yhi); y++)
            {
 
@@ -617,7 +617,7 @@ gdImageCreateFromGd2PartCtx (gdIOCtx * in, int srcx, int srcy, int w, int h)
                          if (!gdGetInt (&ch, in))
                            {
                              ch = 0;
-                             /*printf("EOF while reading file\n"); */
+                             /*php_gd_error("EOF while reading file\n"); */
                              /*goto fail2; */
                            }
                        }
@@ -627,7 +627,7 @@ gdImageCreateFromGd2PartCtx (gdIOCtx * in, int srcx, int srcy, int w, int h)
                          if (ch == EOF)
                            {
                              ch = 0;
-                             /*printf("EOF while reading file\n"); */
+                             /*php_gd_error("EOF while reading file\n"); */
                              /*goto fail2; */
                            }
                        }
@@ -718,7 +718,7 @@ _gdImageGd2 (gdImagePtr im, gdIOCtx * out, int cs, int fmt)
   int bytesPerPixel = im->trueColor ? 4 : 1;
   int compMax = 0;
 
-  /*printf("Trying to write GD2 file\n"); */
+  /*php_gd_error("Trying to write GD2 file\n"); */
 
   /* */
   /* Force fmt to a valid value since we don't return anything. */
@@ -777,7 +777,7 @@ _gdImageGd2 (gdImagePtr im, gdIOCtx * out, int cs, int fmt)
       /* */
       idxPos = gdTell (out);
       idxSize = ncx * ncy * sizeof (t_chunk_info);
-      GD2_DBG (printf ("Index size is %d\n", idxSize));
+      GD2_DBG(php_gd_error("Index size is %d\n", idxSize));
       gdSeek (out, idxPos + idxSize);
 
       chunkIdx = gdCalloc (idxSize * sizeof (t_chunk_info), 1);
@@ -785,8 +785,8 @@ _gdImageGd2 (gdImagePtr im, gdIOCtx * out, int cs, int fmt)
 
   _gdPutColors (im, out);
 
-  GD2_DBG (printf ("Size: %dx%d\n", im->sx, im->sy));
-  GD2_DBG (printf ("Chunks: %dx%d\n", ncx, ncy));
+  GD2_DBG(php_gd_error("Size: %dx%d\n", im->sx, im->sy));
+  GD2_DBG(php_gd_error("Chunks: %dx%d\n", ncx, ncy));
 
   for (cy = 0; (cy < ncy); cy++)
     {
@@ -800,12 +800,12 @@ _gdImageGd2 (gdImagePtr im, gdIOCtx * out, int cs, int fmt)
              yhi = im->sy;
            };
 
-         GD2_DBG (printf ("Processing Chunk (%dx%d), y from %d to %d\n", cx, cy, ylo, yhi));
+         GD2_DBG(php_gd_error("Processing Chunk (%dx%d), y from %d to %d\n", cx, cy, ylo, yhi));
          chunkLen = 0;
          for (y = ylo; (y < yhi); y++)
            {
 
-             /*GD2_DBG(printf("y=%d: ",y)); */
+             GD2_DBG(php_gd_error("y=%d: ",y));
 
              xlo = cx * cs;
              xhi = xlo + cs;
@@ -819,7 +819,7 @@ _gdImageGd2 (gdImagePtr im, gdIOCtx * out, int cs, int fmt)
                  for (x = xlo; x < xhi; x++)
                    {
                      int p = im->pixels[y][x];
-                     /*GD2_DBG(printf("%d...",x)); */
+                     GD2_DBG(php_gd_error("%d...",x));
                      if (im->trueColor)
                        {
                          chunkData[chunkLen++] = gdTrueColorGetAlpha (p);
@@ -837,7 +837,7 @@ _gdImageGd2 (gdImagePtr im, gdIOCtx * out, int cs, int fmt)
                {
                  for (x = xlo; x < xhi; x++)
                    {
-                     /*GD2_DBG(printf("%d, ",x)); */
+                     GD2_DBG(php_gd_error("%d, ",x)); 
 
                      if (im->trueColor)
                        {
@@ -849,7 +849,7 @@ _gdImageGd2 (gdImagePtr im, gdIOCtx * out, int cs, int fmt)
                        }
                    };
                };
-             /*GD2_DBG(printf("y=%d done.\n",y)); */
+             GD2_DBG(php_gd_error("y=%d done.\n",y)); 
            };
          if (fmt == GD2_FMT_COMPRESSED)
            {
@@ -859,18 +859,18 @@ _gdImageGd2 (gdImagePtr im, gdIOCtx * out, int cs, int fmt)
                            (unsigned char *) &chunkData[0],
                            chunkLen) != Z_OK)
                {
-                 printf ("Error from compressing\n");
+                 php_gd_error ("Error from compressing\n");
                }
              else
                {
                  chunkIdx[chunkNum].offset = gdTell (out);
                  chunkIdx[chunkNum++].size = compLen;
-                 GD2_DBG (printf ("Chunk %d size %d offset %d\n", chunkNum, chunkIdx[chunkNum - 1].size, chunkIdx[chunkNum - 1].offset));
+                 GD2_DBG(php_gd_error("Chunk %d size %d offset %d\n", chunkNum, chunkIdx[chunkNum - 1].size, chunkIdx[chunkNum - 1].offset));
 
                  if (gdPutBuf (compData, compLen, out) <= 0)
                    {
                      /* Any alternate suggestions for handling this? */
-                     printf ("Error %d on write\n", errno);
+                     php_gd_error_ex (E_WARNING, "Error %d on write\n", errno);
                    };
                };
            };
@@ -879,13 +879,13 @@ _gdImageGd2 (gdImagePtr im, gdIOCtx * out, int cs, int fmt)
   if (fmt == GD2_FMT_COMPRESSED)
     {
       /* Save the position, write the index, restore position (paranoia). */
-      GD2_DBG (printf ("Seeking %d to write index\n", idxPos));
+      GD2_DBG(php_gd_error("Seeking %d to write index\n", idxPos));
       posSave = gdTell (out);
       gdSeek (out, idxPos);
-      GD2_DBG (printf ("Writing index\n"));
+      GD2_DBG(php_gd_error("Writing index\n"));
       for (x = 0; x < chunkNum; x++)
        {
-         GD2_DBG (printf ("Chunk %d size %d offset %d\n", x, chunkIdx[x].size, chunkIdx[x].offset));
+         GD2_DBG(php_gd_error("Chunk %d size %d offset %d\n", x, chunkIdx[x].size, chunkIdx[x].offset));
          gdPutInt (chunkIdx[x].offset, out);
          gdPutInt (chunkIdx[x].size, out);
        };
@@ -894,13 +894,13 @@ _gdImageGd2 (gdImagePtr im, gdIOCtx * out, int cs, int fmt)
       gdSeek (out, posSave);
     };
 
-  GD2_DBG (printf ("Freeing memory\n"));
+  GD2_DBG(php_gd_error("Freeing memory\n"));
   gdFree (chunkData);
   gdFree (compData);
   gdFree (chunkIdx);
-  GD2_DBG (printf ("Done\n"));
+  GD2_DBG(php_gd_error("Done\n"));
 
-  /*printf("Memory block size is %d\n",gdTell(out)); */
+  /*php_gd_error("Memory block size is %d\n",gdTell(out)); */
 
 }
 
index fc1b587cc8b4315a4cb9d045b9a1564ee8f2b927..df8cc2ec0e693d7710026c098f53bd6f5a8b2122 100644 (file)
@@ -4,6 +4,8 @@
 #include <stdlib.h>
 #include "gd.h"
 
+#include "php.h"
+
 /* Used only when debugging GIF compression code */
 /* #define DEBUGGING_ENVARS */
 
@@ -290,19 +292,24 @@ GetDataBlock_(gdIOCtx *fd, unsigned char *buf)
 static int
 GetDataBlock(gdIOCtx *fd, unsigned char *buf)
 {
- int rv;
- int i;
-
- rv = GetDataBlock_(fd,buf);
- if (VERBOSE)
-  { printf("[GetDataBlock returning %d",rv);
-    if (rv > 0)
-     { printf(":");
-       for (i=0;i<rv;i++) printf(" %02x",buf[i]);
-     }
-    printf("]\n");
-  }
- return(rv);
+       int rv;
+       int i;
+       char *tmp = NULL;
+       
+       rv = GetDataBlock_(fd,buf);
+       if (VERBOSE) {
+               if (rv > 0) {
+                       tmp = emalloc((3*sizeof(char)*rv) + 1);
+                       for (i=0;i<rv;i++) {
+                               sprintf(&tmp[3*sizeof(char)*i], " %02x", buf[i]);
+                       }
+               } else {
+                       tmp = estrdup("");
+               }
+               php_gd_error_ex(E_NOTICE, "[GetDataBlock returning %d: %s]", rv, tmp);
+               efree(tmp);
+       }
+       return(rv);
 }
 
 static int
@@ -352,7 +359,7 @@ GetCode(gdIOCtx *fd, int code_size, int flag)
  int rv;
 
  rv = GetCode_(fd,code_size,flag);
- if (VERBOSE) printf("[GetCode(,%d,%d) returning %d]\n",code_size,flag,rv);
+ if (VERBOSE) php_gd_error_ex(E_NOTICE, "[GetCode(,%d,%d) returning %d]\n",code_size,flag,rv);
  return(rv);
 }
 
@@ -484,7 +491,7 @@ LWZReadByte(gdIOCtx *fd, int flag, int input_code_size)
  int rv;
 
  rv = LWZReadByte_(fd,flag,input_code_size);
- if (VERBOSE) printf("[LWZReadByte(,%d,%d) returning %d]\n",flag,input_code_size,rv);
+ if (VERBOSE) php_gd_error_ex(E_NOTICE, "[LWZReadByte(,%d,%d) returning %d]\n",flag,input_code_size,rv);
  return(rv);
 }
 
index a1bd445d6a689158db82113db0be7fac734ecb61..4c41124f617c101dde961c740e36528edf516be6 100644 (file)
@@ -49,9 +49,8 @@ fatal_jpeg_error (j_common_ptr cinfo)
 {
   jmpbuf_wrapper *jmpbufw;
 
-  fprintf (stderr, "gd-jpeg: JPEG library reports unrecoverable error: ");
+  php_gd_error("gd-jpeg: JPEG library reports unrecoverable error: ");
   (*cinfo->err->output_message) (cinfo);
-  fflush (stderr);
 
   jmpbufw = (jmpbuf_wrapper *) cinfo->client_data;
   jpeg_destroy (cinfo);
@@ -59,16 +58,15 @@ fatal_jpeg_error (j_common_ptr cinfo)
   if (jmpbufw != 0)
     {
       longjmp (jmpbufw->jmpbuf, 1);
-      fprintf (stderr, "gd-jpeg: EXTREMELY fatal error: longjmp"
+      php_gd_error_ex(E_ERROR, "gd-jpeg: EXTREMELY fatal error: longjmp"
               " returned control; terminating\n");
     }
   else
     {
-      fprintf (stderr, "gd-jpeg: EXTREMELY fatal error: jmpbuf"
+      php_gd_error_ex(E_ERROR, "gd-jpeg: EXTREMELY fatal error: jmpbuf"
               " unrecoverable; terminating\n");
     }
 
-  fflush (stderr);
   exit (99);
 }
 
@@ -170,7 +168,7 @@ gdImageJpegCtx (gdImagePtr im, gdIOCtx * outfile, int quality)
                             * sizeof (JSAMPLE));
   if (row == 0)
     {
-      fprintf (stderr, "gd-jpeg: error: unable to allocate JPEG row "
+      php_gd_error("gd-jpeg: error: unable to allocate JPEG row "
               "structure: gdCalloc returns NULL\n");
       jpeg_destroy_compress (&cinfo);
       return;
@@ -192,7 +190,7 @@ gdImageJpegCtx (gdImagePtr im, gdIOCtx * outfile, int quality)
   if (im->trueColor)
     {
 #if BITS_IN_JSAMPLE == 12
-      fprintf (stderr, "gd-jpeg: error: jpeg library was compiled for 12-bit\n"
+      php_gd_error("gd-jpeg: error: jpeg library was compiled for 12-bit\n"
         "precision. This is mostly useless, because JPEGs on the web are\n"
         "8-bit and such versions of the jpeg library won't read or write\n"
               "them. GD doesn't support these unusual images. Edit your\n"
@@ -212,7 +210,7 @@ gdImageJpegCtx (gdImagePtr im, gdIOCtx * outfile, int quality)
 
          nlines = jpeg_write_scanlines (&cinfo, rowptr, 1);
          if (nlines != 1)
-           fprintf (stderr, "gd_jpeg: warning: jpeg_write_scanlines"
+           php_gd_error_ex(E_WARNING, "gd_jpeg: warning: jpeg_write_scanlines"
                     " returns %u -- expected 1\n", nlines);
        }
     }
@@ -244,7 +242,7 @@ gdImageJpegCtx (gdImagePtr im, gdIOCtx * outfile, int quality)
 
          nlines = jpeg_write_scanlines (&cinfo, rowptr, 1);
          if (nlines != 1)
-           fprintf (stderr, "gd_jpeg: warning: jpeg_write_scanlines"
+           php_gd_error_ex(E_WARNING, "gd_jpeg: warning: jpeg_write_scanlines"
                     " returns %u -- expected 1\n", nlines);
        }
     }
@@ -314,17 +312,17 @@ gdImageCreateFromJpegCtx (gdIOCtx * infile)
 
   retval = jpeg_read_header (&cinfo, TRUE);
   if (retval != JPEG_HEADER_OK)
-    fprintf (stderr, "gd-jpeg: warning: jpeg_read_header returns"
+    php_gd_error_ex(E_WARNING, "gd-jpeg: warning: jpeg_read_header returns"
             " %d, expected %d\n", retval, JPEG_HEADER_OK);
 
   if (cinfo.image_height > INT_MAX)
-    fprintf (stderr, "gd-jpeg: warning: JPEG image height (%u) is"
+    php_gd_error_ex(E_WARNING, "gd-jpeg: warning: JPEG image height (%u) is"
             " greater than INT_MAX (%d) (and thus greater than"
             " gd can handle)", cinfo.image_height,
             INT_MAX);
 
   if (cinfo.image_width > INT_MAX)
-    fprintf (stderr, "gd-jpeg: warning: JPEG image width (%u) is"
+    php_gd_error_ex(E_WARNING, "gd-jpeg: warning: JPEG image width (%u) is"
             " greater than INT_MAX (%d) (and thus greater than"
             " gd can handle)\n", cinfo.image_width, INT_MAX);
 
@@ -332,7 +330,7 @@ gdImageCreateFromJpegCtx (gdIOCtx * infile)
                               (int) cinfo.image_height);
   if (im == 0)
     {
-      fprintf (stderr, "gd-jpeg error: cannot allocate gdImage"
+      php_gd_error("gd-jpeg error: cannot allocate gdImage"
               " struct\n");
       goto error;
     }
@@ -344,7 +342,7 @@ gdImageCreateFromJpegCtx (gdIOCtx * infile)
   cinfo.out_color_space = JCS_RGB;
 
   if (jpeg_start_decompress (&cinfo) != TRUE)
-    fprintf (stderr, "gd-jpeg: warning: jpeg_start_decompress"
+    php_gd_error("gd-jpeg: warning: jpeg_start_decompress"
             " reports suspended data source\n");
 
 #ifdef JPEG_DEBUG
@@ -409,14 +407,14 @@ gdImageCreateFromJpegCtx (gdIOCtx * infile)
 #endif
   if (cinfo.output_components != 3)
     {
-      fprintf (stderr, "gd-jpeg: error: JPEG color quantization"
+      php_gd_error_ex(E_WARNING, "gd-jpeg: error: JPEG color quantization"
               " request resulted in output_components == %d"
               " (expected 3)\n", cinfo.output_components);
       goto error;
     }
 
 #if BITS_IN_JSAMPLE == 12
-  fprintf (stderr, "gd-jpeg: error: jpeg library was compiled for 12-bit\n"
+  php_gd_error("gd-jpeg: error: jpeg library was compiled for 12-bit\n"
         "precision. This is mostly useless, because JPEGs on the web are\n"
         "8-bit and such versions of the jpeg library won't read or write\n"
           "them. GD doesn't support these unusual images. Edit your\n"
@@ -428,7 +426,7 @@ gdImageCreateFromJpegCtx (gdIOCtx * infile)
   row = gdCalloc (cinfo.output_width * 3, sizeof (JSAMPLE));
   if (row == 0)
     {
-      fprintf (stderr, "gd-jpeg: error: unable to allocate row for"
+      php_gd_error("gd-jpeg: error: unable to allocate row for"
               " JPEG scanline: gdCalloc returns NULL\n");
       goto error;
     }
@@ -439,7 +437,7 @@ gdImageCreateFromJpegCtx (gdIOCtx * infile)
       nrows = jpeg_read_scanlines (&cinfo, rowptr, 1);
       if (nrows != 1)
        {
-         fprintf (stderr, "gd-jpeg: error: jpeg_read_scanlines"
+         php_gd_error_ex(E_WARNING, "gd-jpeg: error: jpeg_read_scanlines"
                   " returns %u, expected 1\n", nrows);
          goto error;
        }
@@ -450,7 +448,7 @@ gdImageCreateFromJpegCtx (gdIOCtx * infile)
     }
 
   if (jpeg_finish_decompress (&cinfo) != TRUE)
-    fprintf (stderr, "gd-jpeg: warning: jpeg_finish_decompress"
+    php_gd_error("gd-jpeg: warning: jpeg_finish_decompress"
             " reports suspended data source\n");
 
 
index f605d98f6c3b54810b89ef7f1ba829d15df18b54..4671f83cc0ed252ed7998024506cde2962c41344 100644 (file)
@@ -59,15 +59,12 @@ gdPngErrorHandler (png_structp png_ptr, png_const_charp msg)
    * regardless of whether _BSD_SOURCE or anything else has (or has not)
    * been defined. */
 
-  fprintf (stderr, "gd-png:  fatal libpng error: %s\n", msg);
-  fflush (stderr);
+  php_gd_error_ex(E_ERROR, "gd-png:  fatal libpng error: %s\n", msg);
 
   jmpbuf_ptr = png_get_error_ptr (png_ptr);
   if (jmpbuf_ptr == NULL)
     {                          /* we are completely hosed now */
-      fprintf (stderr,
-              "gd-png:  EXTREMELY fatal error: jmpbuf unrecoverable; terminating.\n");
-      fflush (stderr);
+      php_gd_error_ex(E_ERROR, "gd-png:  EXTREMELY fatal error: jmpbuf unrecoverable; terminating.\n");
       exit (99);
     }
 
@@ -148,14 +145,14 @@ gdImageCreateFromPngCtx (gdIOCtx * infile)
 #endif
   if (png_ptr == NULL)
     {
-      fprintf (stderr, "gd-png error: cannot allocate libpng main struct\n");
+      php_gd_error("gd-png error: cannot allocate libpng main struct\n");
       return NULL;
     }
 
   info_ptr = png_create_info_struct (png_ptr);
   if (info_ptr == NULL)
     {
-      fprintf (stderr, "gd-png error: cannot allocate libpng info struct\n");
+      php_gd_error("gd-png error: cannot allocate libpng info struct\n");
       png_destroy_read_struct (&png_ptr, NULL, NULL);
       return NULL;
     }
@@ -169,7 +166,7 @@ gdImageCreateFromPngCtx (gdIOCtx * infile)
 #ifndef PNG_SETJMP_NOT_SUPPORTED
   if (setjmp (gdPngJmpbufStruct.jmpbuf))
     {
-      fprintf (stderr, "gd-png error: setjmp returns error condition\n");
+      php_gd_error("gd-png error: setjmp returns error condition\n");
       png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
       return NULL;
     }
@@ -193,7 +190,7 @@ gdImageCreateFromPngCtx (gdIOCtx * infile)
     }
   if (im == NULL)
     {
-      fprintf (stderr, "gd-png error: cannot allocate gdImage struct\n");
+      php_gd_error("gd-png error: cannot allocate gdImage struct\n");
       png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
       gdFree (image_data);
       gdFree (row_pointers);
@@ -209,7 +206,7 @@ gdImageCreateFromPngCtx (gdIOCtx * infile)
     case PNG_COLOR_TYPE_PALETTE:
       png_get_PLTE (png_ptr, info_ptr, &palette, &num_palette);
 #ifdef DEBUG
-      fprintf (stderr, "gd-png color_type is palette, colors: %d\n",
+      php_gd_error("gd-png color_type is palette, colors: %d\n",
               num_palette);
 #endif /* DEBUG */
       if (png_get_valid (png_ptr, info_ptr, PNG_INFO_tRNS))
@@ -238,7 +235,7 @@ gdImageCreateFromPngCtx (gdIOCtx * infile)
       /* create a fake palette and check for single-shade transparency */
       if ((palette = (png_colorp) gdMalloc (256 * sizeof (png_color))) == NULL)
        {
-         fprintf (stderr, "gd-png error: cannot allocate gray palette\n");
+         php_gd_error("gd-png error: cannot allocate gray palette\n");
          png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
          return NULL;
        }
@@ -306,13 +303,13 @@ gdImageCreateFromPngCtx (gdIOCtx * infile)
   rowbytes = png_get_rowbytes (png_ptr, info_ptr);
   if ((image_data = (png_bytep) gdMalloc (rowbytes * height)) == NULL)
     {
-      fprintf (stderr, "gd-png error: cannot allocate image data\n");
+      php_gd_error("gd-png error: cannot allocate image data\n");
       png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
       return NULL;
     }
   if ((row_pointers = (png_bytepp) gdMalloc (height * sizeof (png_bytep))) == NULL)
     {
-      fprintf (stderr, "gd-png error: cannot allocate row pointers\n");
+      php_gd_error("gd-png error: cannot allocate row pointers\n");
       png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
       gdFree (image_data);
       return NULL;
@@ -401,7 +398,7 @@ gdImageCreateFromPngCtx (gdIOCtx * infile)
        {
          if (!open[i])
            {
-             fprintf (stderr, "gd-png warning: image data references out-of-range"
+             php_gd_error("gd-png warning: image data references out-of-range"
                       " color index (%d)\n", i);
            }
        }
@@ -466,14 +463,14 @@ gdImagePngCtx (gdImagePtr im, gdIOCtx * outfile)
 #endif
   if (png_ptr == NULL)
     {
-      fprintf (stderr, "gd-png error: cannot allocate libpng main struct\n");
+      php_gd_error("gd-png error: cannot allocate libpng main struct\n");
       return;
     }
 
   info_ptr = png_create_info_struct (png_ptr);
   if (info_ptr == NULL)
     {
-      fprintf (stderr, "gd-png error: cannot allocate libpng info struct\n");
+      php_gd_error("gd-png error: cannot allocate libpng info struct\n");
       png_destroy_write_struct (&png_ptr, (png_infopp) NULL);
       return;
     }
@@ -481,7 +478,7 @@ gdImagePngCtx (gdImagePtr im, gdIOCtx * outfile)
 #ifndef PNG_SETJMP_NOT_SUPPORTED
   if (setjmp (gdPngJmpbufStruct.jmpbuf))
     {
-      fprintf (stderr, "gd-png error: setjmp returns error condition\n");
+      php_gd_error("gd-png error: setjmp returns error condition\n");
       png_destroy_write_struct (&png_ptr, &info_ptr);
       return;
     }
@@ -672,14 +669,14 @@ gdImagePngCtx (gdImagePtr im, gdIOCtx * outfile)
       row_pointers = gdMalloc (sizeof (png_bytep) * height);
       if (row_pointers == NULL)
        {
-         fprintf (stderr, "gd-png error: unable to allocate row_pointers\n");
+         php_gd_error("gd-png error: unable to allocate row_pointers\n");
        }
       for (j = 0; j < height; ++j)
        {
          int bo = 0;
          if ((row_pointers[j] = (png_bytep) gdMalloc (width * channels)) == NULL)
            {
-             fprintf (stderr, "gd-png error: unable to allocate rows\n");
+             php_gd_error("gd-png error: unable to allocate rows\n");
              for (i = 0; i < j; ++i)
                gdFree (row_pointers[i]);
              return;
@@ -719,13 +716,13 @@ gdImagePngCtx (gdImagePtr im, gdIOCtx * outfile)
          row_pointers = gdMalloc (sizeof (png_bytep) * height);
          if (row_pointers == NULL)
            {
-             fprintf (stderr, "gd-png error: unable to allocate row_pointers\n");
+             php_gd_error("gd-png error: unable to allocate row_pointers\n");
            }
          for (j = 0; j < height; ++j)
            {
              if ((row_pointers[j] = (png_bytep) gdMalloc (width)) == NULL)
                {
-                 fprintf (stderr, "gd-png error: unable to allocate rows\n");
+                 php_gd_error("gd-png error: unable to allocate rows\n");
                  for (i = 0; i < j; ++i)
                    gdFree (row_pointers[i]);
                  return;
index d640a2193daf5bf8f4605a8a28a65c5fa7bc7901..10bc6aa7479d0c7c8a8851470d138f5854946eb2 100644 (file)
@@ -41,12 +41,12 @@ gdImageCreateFromPngSource (gdSourcePtr inSource)
 void
 gdImagePngToSink (gdImagePtr im, gdSinkPtr outSink)
 {
-  fprintf(stderr,"PNG support is not available\n");
+  php_gd_error("PNG support is not available\n");
 }
 gdImagePtr
 gdImageCreateFromPngSource (gdSourcePtr inSource)
 {
-  fprintf(stderr,"PNG support is not available\n");
+  php_gd_error("PNG support is not available\n");
   return NULL;
 }
 #endif /* HAVE_LIBPNG */
index e0abd94c308002dfaedf3fc3e0dc52a143d4095f..860f70c0a54cb88cb2db0a7e2f3f46a81c80f294 100644 (file)
@@ -105,7 +105,7 @@ gdImageWBMPCtx (gdImagePtr image, int fg, gdIOCtx * out)
 
   /* create the WBMP */
   if ((wbmp = createwbmp (gdImageSX (image), gdImageSY (image), WBMP_WHITE)) == NULL)
-    fprintf (stderr, "Could not create WBMP\n");
+    php_gd_error("Could not create WBMP\n");
 
   /* fill up the WBMP structure */
   pos = 0;
@@ -123,7 +123,7 @@ gdImageWBMPCtx (gdImagePtr image, int fg, gdIOCtx * out)
 
   /* write the WBMP to a gd file descriptor */
   if (writewbmp (wbmp, &gd_putout, out))
-    fprintf (stderr, "Could not save WBMP\n");
+    php_gd_error("Could not save WBMP\n");
   /* des submitted this bugfix: gdFree the memory. */
   freewbmp (wbmp);
 }
index 21eb2d373d6f7ac414a8750b3dd47d387632d4d6..30609cde132b4881b8eadfb86b1dc1afe7e91ec4 100644 (file)
@@ -72,13 +72,15 @@ debug (const char *format,...)
 static void
 error (const char *format,...)
 {
-  va_list args;
-
-  va_start (args, format);
-  fprintf (stderr, "%s: ", LIBNAME);
-  vfprintf (stderr, format, args);
-  fprintf (stderr, "\n");
-  va_end (args);
+       va_list args;
+       char *tmp;
+       TSRMLS_FETCH();
+       
+       va_start(args, format);
+       vspprintf(&tmp, 0, format, args);
+       va_end(args);
+       php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s: %s", LIBNAME, tmp);
+       efree(tmp);
 }
 
 /* DetectKanjiCode() derived from DetectCodeType() by Ken Lunde. */
index bd346bbc063821610b77fbe770dc631d18d43392..4687fa870be2d67475750092f15d025b5db6f3a4 100644 (file)
@@ -115,7 +115,7 @@ gdImageCreateFromXpm (char *filename)
 
       colors[i] = gdImageColorResolve (im, red, green, blue);
       if (colors[i] == -1)
-       fprintf (stderr, "ARRRGH\n");
+       php_gd_error("ARRRGH\n");
     }
 
   apixel = (char *) gdMalloc (image.cpp + 1);