[master] Copied png_debug macros from pngpriv.h into pngtest.c and removed

"#include pngpriv.h" from pngtest.c, to avoid setting a bad example.
This commit is contained in:
Glenn Randers-Pehrson 2011-05-02 14:11:10 -05:00
parent 6b4dee12f5
commit 3bdde42e40
3 changed files with 55 additions and 36 deletions

View File

@ -28,6 +28,8 @@ Changes since the last public release (1.4.7):
version 1.4.8beta01 [May 2, 2011]
Undef "_ALL_SOURCE" for AIX, to prevent "jmpbuf" from being redefined.
Copied png_debug macros from pngpriv.h into pngtest.c and removed
"#include pngpriv.h" from pngtest.c, to avoid setting a bad example.
Send comments/corrections/commendations to glennrp at users.sourceforge.net
or to png-mng-implement at lists.sf.net (subscription required; visit

View File

@ -2796,6 +2796,8 @@ version 1.4.7 [April 9, 2011]
version 1.4.8beta01 [May 2, 2011]
Undef "_ALL_SOURCE" for AIX, to prevent "jmpbuf" from being redefined.
Copied png_debug macros from pngpriv.h into pngtest.c and removed
"#include pngpriv.h" from pngtest.c, to avoid setting a bad example.
Send comments/corrections/commendations to glennrp at users.sourceforge.net
or to png-mng-implement at lists.sf.net (subscription required; visit

View File

@ -31,8 +31,13 @@
* of files at once by typing "pngtest -m file1.png file2.png ..."
*/
#include "zlib.h"
#include "png.h"
#include "pngpriv.h"
/* Copied from pngpriv.h but only used in error messages below. */
#ifndef PNG_ZBUF_SIZE
# define PNG_ZBUF_SIZE 8192
#endif
# include <stdio.h>
# include <stdlib.h>
@ -47,6 +52,16 @@
# define PNG_DEBUG 0
#endif
#if PNG_DEBUG > 1
# define pngtest_debug(m) ((void)fprintf(stderr, m "\n"))
# define pngtest_debug1(m,p1) ((void)fprintf(stderr, m "\n", p1))
# define pngtest_debug2(m,p1,p2) ((void)fprintf(stderr, m "\n", p1, p2))
#else
# define pngtest_debug(m) ((void)0)
# define pngtest_debug1(m,p1) ((void)0)
# define pngtest_debug2(m,p1,p2) ((void)0)
#endif
#if !PNG_DEBUG
# define SINGLE_ROWBUF_ALLOC /* Makes buffer overruns easier to nail */
#endif
@ -527,16 +542,16 @@ static int maximum_allocation = 0;
static int total_allocation = 0;
static int num_allocations = 0;
png_voidp png_debug_malloc
png_voidp pngtest_debug_malloc
PNGARG((png_structp png_ptr, png_alloc_size_t size));
void png_debug_free PNGARG((png_structp png_ptr, png_voidp ptr));
void pngtest_debug_free PNGARG((png_structp png_ptr, png_voidp ptr));
png_voidp
png_debug_malloc(png_structp png_ptr, png_alloc_size_t size)
pngtest_debug_malloc(png_structp png_ptr, png_alloc_size_t size)
{
/* png_malloc has already tested for NULL; png_create_struct calls
* png_debug_malloc directly, with png_ptr == NULL which is OK
* pngtest_debug_malloc directly, with png_ptr == NULL which is OK
*/
if (size == 0)
@ -559,13 +574,13 @@ png_debug_malloc(png_structp png_ptr, png_alloc_size_t size)
pinfo->pointer = png_malloc(png_ptr, size);
/* Restore malloc_fn and free_fn */
png_set_mem_fn(png_ptr,
NULL, png_debug_malloc, png_debug_free);
NULL, pngtest_debug_malloc, pngtest_debug_free);
if (size != 0 && pinfo->pointer == NULL)
{
current_allocation -= size;
total_allocation -= size;
png_error(png_ptr,
"out of memory in pngtest->png_debug_malloc");
"out of memory in pngtest->pngtest_debug_malloc");
}
pinfo->next = pinformation;
pinformation = pinfo;
@ -580,10 +595,10 @@ png_debug_malloc(png_structp png_ptr, png_alloc_size_t size)
/* Free a pointer. It is removed from the list at the same time. */
void
png_debug_free(png_structp png_ptr, png_voidp ptr)
pngtest_debug_free(png_structp png_ptr, png_voidp ptr)
{
if (png_ptr == NULL)
fprintf(STDERR, "NULL pointer to png_debug_free.\n");
fprintf(STDERR, "NULL pointer to pngtest_debug_free.\n");
if (ptr == 0)
{
#if 0 /* This happens all the time. */
@ -742,12 +757,12 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
return (1);
}
png_debug(0, "Allocating read and write structures");
pngtest_debug("Allocating read and write structures");
#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
read_ptr =
png_create_read_struct_2(PNG_LIBPNG_VER_STRING, NULL,
NULL, NULL, NULL,
(png_malloc_ptr)png_debug_malloc, (png_free_ptr)png_debug_free);
(png_malloc_ptr)pngtest_debug_malloc, (png_free_ptr)pngtest_debug_free);
#else
read_ptr =
png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
@ -770,7 +785,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
write_ptr =
png_create_write_struct_2(PNG_LIBPNG_VER_STRING, NULL,
NULL, NULL, NULL, png_debug_malloc, png_debug_free);
NULL, NULL, NULL, pngtest_debug_malloc, pngtest_debug_free);
#else
write_ptr =
png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
@ -780,7 +795,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
pngtest_warning);
#endif
#endif
png_debug(0, "Allocating read_info, write_info and end_info structures");
pngtest_debug("Allocating read_info, write_info and end_info structures");
read_info_ptr = png_create_info_struct(read_ptr);
end_info_ptr = png_create_info_struct(read_ptr);
#ifdef PNG_WRITE_SUPPORTED
@ -789,7 +804,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
#endif
#ifdef PNG_SETJMP_SUPPORTED
png_debug(0, "Setting jmpbuf for read struct");
pngtest_debug("Setting jmpbuf for read struct");
#ifdef USE_FAR_KEYWORD
if (setjmp(jmpbuf))
#else
@ -813,7 +828,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
#endif
#ifdef PNG_WRITE_SUPPORTED
png_debug(0, "Setting jmpbuf for write struct");
pngtest_debug("Setting jmpbuf for write struct");
#ifdef USE_FAR_KEYWORD
if (setjmp(jmpbuf))
#else
@ -836,7 +851,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
#endif
#endif
png_debug(0, "Initializing input and output streams");
pngtest_debug("Initializing input and output streams");
#ifdef PNG_STDIO_SUPPORTED
png_init_io(read_ptr, fpin);
# ifdef PNG_WRITE_SUPPORTED
@ -896,10 +911,10 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
NULL, 0);
#endif
png_debug(0, "Reading info struct");
pngtest_debug("Reading info struct");
png_read_info(read_ptr, read_info_ptr);
png_debug(0, "Transferring info struct");
pngtest_debug("Transferring info struct");
{
int interlace_type, compression_type, filter_type;
@ -1086,7 +1101,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
if (png_get_text(read_ptr, read_info_ptr, &text_ptr, &num_text) > 0)
{
png_debug1(0, "Handling %d iTXt/tEXt/zTXt chunks", num_text);
pngtest_debug1("Handling %d iTXt/tEXt/zTXt chunks", num_text);
png_set_text(write_ptr, write_info_ptr, text_ptr, num_text);
}
}
@ -1156,7 +1171,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
#endif
#ifdef PNG_WRITE_SUPPORTED
png_debug(0, "Writing info struct");
pngtest_debug("Writing info struct");
/* If we wanted, we could write info in two steps:
* png_write_info_before_PLTE(write_ptr, write_info_ptr);
@ -1199,12 +1214,12 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
#endif
#ifdef SINGLE_ROWBUF_ALLOC
png_debug(0, "Allocating row buffer...");
pngtest_debug("Allocating row buffer...");
row_buf = (png_bytep)png_malloc(read_ptr,
png_get_rowbytes(read_ptr, read_info_ptr));
png_debug1(0, "0x%08lx", (unsigned long)row_buf);
pngtest_debug1("0x%08lx", (unsigned long)row_buf);
#endif /* SINGLE_ROWBUF_ALLOC */
png_debug(0, "Writing row data");
pngtest_debug("Writing row data");
#if defined(PNG_READ_INTERLACING_SUPPORTED) || \
defined(PNG_WRITE_INTERLACING_SUPPORTED)
@ -1223,14 +1238,14 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
#endif
for (pass = 0; pass < num_pass; pass++)
{
png_debug1(0, "Writing row data for pass %d", pass);
pngtest_debug1("Writing row data for pass %d", pass);
for (y = 0; y < height; y++)
{
#ifndef SINGLE_ROWBUF_ALLOC
png_debug2(0, "Allocating row buffer (pass %d, y = %ld)...", pass, y);
pngtest_debug2("Allocating row buffer (pass %d, y = %ld)...", pass, y);
row_buf = (png_bytep)png_malloc(read_ptr,
png_get_rowbytes(read_ptr, read_info_ptr));
png_debug2(0, "0x%08lx (%ld bytes)", (unsigned long)row_buf,
pngtest_debug2("0x%08lx (%ld bytes)", (unsigned long)row_buf,
png_get_rowbytes(read_ptr, read_info_ptr));
#endif /* !SINGLE_ROWBUF_ALLOC */
png_read_rows(read_ptr, (png_bytepp)&row_buf, NULL, 1);
@ -1250,7 +1265,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
#endif /* PNG_WRITE_SUPPORTED */
#ifndef SINGLE_ROWBUF_ALLOC
png_debug2(0, "Freeing row buffer (pass %d, y = %ld)", pass, y);
pngtest_debug2("Freeing row buffer (pass %d, y = %ld)", pass, y);
png_free(read_ptr, row_buf);
row_buf = NULL;
#endif /* !SINGLE_ROWBUF_ALLOC */
@ -1264,7 +1279,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
png_free_data(write_ptr, write_info_ptr, PNG_FREE_UNKN, -1);
#endif
png_debug(0, "Reading and writing end_info data");
pngtest_debug("Reading and writing end_info data");
png_read_end(read_ptr, end_info_ptr);
#ifdef PNG_TEXT_SUPPORTED
@ -1274,7 +1289,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
if (png_get_text(read_ptr, end_info_ptr, &text_ptr, &num_text) > 0)
{
png_debug1(0, "Handling %d iTXt/tEXt/zTXt chunks", num_text);
pngtest_debug1("Handling %d iTXt/tEXt/zTXt chunks", num_text);
png_set_text(write_ptr, write_end_info_ptr, text_ptr, num_text);
}
}
@ -1335,26 +1350,26 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
}
#endif
png_debug(0, "Destroying data structs");
pngtest_debug("Destroying data structs");
#ifdef SINGLE_ROWBUF_ALLOC
png_debug(1, "destroying row_buf for read_ptr");
pngtest_debug("destroying row_buf for read_ptr");
png_free(read_ptr, row_buf);
row_buf = NULL;
#endif /* SINGLE_ROWBUF_ALLOC */
png_debug(1, "destroying read_ptr, read_info_ptr, end_info_ptr");
pngtest_debug("destroying read_ptr, read_info_ptr, end_info_ptr");
png_destroy_read_struct(&read_ptr, &read_info_ptr, &end_info_ptr);
#ifdef PNG_WRITE_SUPPORTED
png_debug(1, "destroying write_end_info_ptr");
pngtest_debug("destroying write_end_info_ptr");
png_destroy_info_struct(write_ptr, &write_end_info_ptr);
png_debug(1, "destroying write_ptr, write_info_ptr");
pngtest_debug("destroying write_ptr, write_info_ptr");
png_destroy_write_struct(&write_ptr, &write_info_ptr);
#endif
png_debug(0, "Destruction complete.");
pngtest_debug("Destruction complete.");
FCLOSE(fpin);
FCLOSE(fpout);
png_debug(0, "Opening files for comparison");
pngtest_debug("Opening files for comparison");
if ((fpin = fopen(inname, "rb")) == NULL)
{
fprintf(STDERR, "Could not find file %s\n", inname);