Commit 819eaf0e authored by Kenneth Moreland's avatar Kenneth Moreland

Merge branch 'better-diagnostic-macros' into 'master'

Update the diagnostics macros

See merge request !6
parents 32515220 ef7bdd67
......@@ -111,8 +111,8 @@ static MPI_Request getMPIRequest(IceTCommRequest icet_request)
}
if (icet_request->magic_number != ICET_MPI_REQUEST_MAGIC_NUMBER) {
icetRaiseError("Request object is not from the MPI communicator.",
ICET_INVALID_VALUE);
icetRaiseError(ICET_INVALID_VALUE,
"Request object is not from the MPI communicator.");
return MPI_REQUEST_NULL;
}
......@@ -122,14 +122,14 @@ static MPI_Request getMPIRequest(IceTCommRequest icet_request)
static void setMPIRequest(IceTCommRequest icet_request, MPI_Request mpi_request)
{
if (icet_request == ICET_COMM_REQUEST_NULL) {
icetRaiseError("Cannot set MPI request in null request.",
ICET_SANITY_CHECK_FAIL);
icetRaiseError(ICET_SANITY_CHECK_FAIL,
"Cannot set MPI request in null request.");
return;
}
if (icet_request->magic_number != ICET_MPI_REQUEST_MAGIC_NUMBER) {
icetRaiseError("Request object is not from the MPI communicator.",
ICET_SANITY_CHECK_FAIL);
icetRaiseError(ICET_SANITY_CHECK_FAIL,
"Request object is not from the MPI communicator.");
return;
}
......@@ -143,8 +143,8 @@ static IceTCommRequest create_request(void)
request = (IceTCommRequest)malloc(sizeof(struct IceTCommRequestStruct));
if (request == NULL) {
icetRaiseError("Could not allocate memory for IceTCommRequest",
ICET_OUT_OF_MEMORY);
icetRaiseError(ICET_OUT_OF_MEMORY,
"Could not allocate memory for IceTCommRequest");
return NULL;
}
......@@ -152,8 +152,8 @@ static IceTCommRequest create_request(void)
request->internals=malloc(sizeof(struct IceTMPICommRequestInternalsStruct));
if (request->internals == NULL) {
free(request);
icetRaiseError("Could not allocate memory for IceTCommRequest",
ICET_OUT_OF_MEMORY);
icetRaiseError(ICET_OUT_OF_MEMORY,
"Could not allocate memory for IceTCommRequest");
return NULL;
}
......@@ -166,9 +166,9 @@ static void destroy_request(IceTCommRequest request)
{
MPI_Request mpi_request = getMPIRequest(request);
if (mpi_request != MPI_REQUEST_NULL) {
icetRaiseError("Destroying MPI request that is not NULL."
" Probably leaking MPI requests.",
ICET_SANITY_CHECK_FAIL);
icetRaiseError(ICET_SANITY_CHECK_FAIL,
"Destroying MPI request that is not NULL."
" Probably leaking MPI requests.");
}
free(request->internals);
......@@ -178,14 +178,13 @@ static void destroy_request(IceTCommRequest request)
#ifdef BREAK_ON_MPI_ERROR
static void ErrorHandler(MPI_Comm *comm, int *errorno, ...)
{
char error_msg[MPI_MAX_ERROR_STRING+16];
char error_msg[MPI_MAX_ERROR_STRING];
int mpi_error_len;
(void)comm;
strcpy(error_msg, "MPI ERROR:\n");
MPI_Error_string(*errorno, error_msg + strlen(error_msg), &mpi_error_len);
MPI_Error_string(*errorno, error_msg, &mpi_error_len);
icetRaiseError(error_msg, ICET_INVALID_OPERATION);
icetRaiseError(ICET_INVALID_OPERATION, "MPI ERROR:\n%s", error_msg);
icetDebugBreak();
}
#endif
......@@ -203,8 +202,8 @@ IceTCommunicator icetCreateMPICommunicator(MPI_Comm mpi_comm)
comm = malloc(sizeof(struct IceTCommunicatorStruct));
if (comm == NULL) {
icetRaiseError("Could not allocate memory for IceTCommunicator.",
ICET_OUT_OF_MEMORY);
icetRaiseError(ICET_OUT_OF_MEMORY,
"Could not allocate memory for IceTCommunicator.");
return NULL;
}
......@@ -229,8 +228,8 @@ IceTCommunicator icetCreateMPICommunicator(MPI_Comm mpi_comm)
comm->data = malloc(sizeof(MPI_Comm));
if (comm->data == NULL) {
free(comm);
icetRaiseError("Could not allocate memory for IceTCommunicator.",
ICET_OUT_OF_MEMORY);
icetRaiseError(ICET_OUT_OF_MEMORY,
"Could not allocate memory for IceTCommunicator.");
return NULL;
}
MPI_Comm_dup(mpi_comm, (MPI_Comm *)comm->data);
......@@ -315,8 +314,9 @@ static void MPIBarrier(IceTCommunicator self)
case ICET_FLOAT: mpi_type = MPI_FLOAT; break; \
case ICET_DOUBLE: mpi_type = MPI_DOUBLE; break; \
default: \
icetRaiseError("MPI Communicator received bad data type.", \
ICET_INVALID_ENUM); \
icetRaiseError(ICET_INVALID_ENUM, \
"MPI Communicator received bad data type 0x%X.", \
icet_type); \
mpi_type = MPI_BYTE; \
break; \
}
......@@ -540,8 +540,8 @@ static int MPIWaitany(IceTCommunicator self,
mpi_requests = malloc(sizeof(MPI_Request)*count);
if (mpi_requests == NULL) {
icetRaiseError("Could not allocate array for MPI requests.",
ICET_OUT_OF_MEMORY);
icetRaiseError(ICET_OUT_OF_MEMORY,
"Could not allocate array for MPI requests.");
return -1;
}
......
......@@ -38,9 +38,9 @@ static void inflateBuffer(IceTUByte *buffer,
void icetGLDrawCallback(IceTGLDrawCallbackType func)
{
if (!icetGLIsInitialized()) {
icetRaiseError("IceT OpenGL layer not initialized."
" Call icetGLInitialize.",
ICET_INVALID_OPERATION);
icetRaiseError(ICET_INVALID_OPERATION,
"IceT OpenGL layer not initialized."
" Call icetGLInitialize.");
return;
}
......@@ -97,9 +97,9 @@ static void setupOpenGLRender(IceTDouble *projection_matrix,
*ok_to_proceed = ICET_FALSE;
if (!icetGLIsInitialized()) {
icetRaiseError("IceT OpenGL layer not initialized."
" Call icetGLInitialize.",
ICET_INVALID_OPERATION);
icetRaiseError(ICET_INVALID_OPERATION,
"IceT OpenGL layer not initialized."
" Call icetGLInitialize.");
return;
}
......@@ -117,8 +117,8 @@ static void setupOpenGLRender(IceTDouble *projection_matrix,
/* Check the GL callback. */
icetGetPointerv(ICET_GL_DRAW_FUNCTION, &value);
if (value == NULL) {
icetRaiseError("GL Drawing function not set. Call icetGLDrawCallback.",
ICET_INVALID_OPERATION);
icetRaiseError(ICET_INVALID_OPERATION,
"GL Drawing function not set. Call icetGLDrawCallback.");
return;
}
......
......@@ -29,8 +29,9 @@ void icetGLDrawCallbackFunction(const IceTDouble *projection_matrix,
/* Check OpenGL state. */
{
if ((gl_viewport[2] != width) || (gl_viewport[3] != height)) {
icetRaiseError("OpenGL viewport different than expected."
" Was it changed?", ICET_SANITY_CHECK_FAIL);
icetRaiseError(ICET_SANITY_CHECK_FAIL,
"OpenGL viewport different than expected."
" Was it changed?");
}
}
......@@ -102,7 +103,8 @@ void icetGLDrawCallbackFunction(const IceTDouble *projection_matrix,
colorBuffer + 4*( readback_viewport[0]
+ width*readback_viewport[1]));
} else if (color_format != ICET_IMAGE_COLOR_NONE) {
icetRaiseError("Invalid color format.", ICET_SANITY_CHECK_FAIL);
icetRaiseError(ICET_SANITY_CHECK_FAIL,
"Invalid color format 0x%X.", color_format);
}
if (depth_format == ICET_IMAGE_DEPTH_FLOAT) {
......@@ -116,7 +118,8 @@ void icetGLDrawCallbackFunction(const IceTDouble *projection_matrix,
depthBuffer + ( readback_viewport[0]
+ width*readback_viewport[1]));
} else if (depth_format != ICET_IMAGE_DEPTH_NONE) {
icetRaiseError("Invalid depth format.", ICET_SANITY_CHECK_FAIL);
icetRaiseError(ICET_SANITY_CHECK_FAIL,
"Invalid depth format 0x%X.", depth_format);
}
glPixelStorei(GL_PACK_ROW_LENGTH, 0);
......
......@@ -17,8 +17,8 @@ static void gl_destroy(void);
void icetGLInitialize(void)
{
if (icetGLIsInitialized()) {
icetRaiseWarning("icetGLInitialize called multiple times.",
ICET_INVALID_OPERATION);
icetRaiseWarning(ICET_INVALID_OPERATION,
"icetGLInitialize called multiple times.");
}
icetStateSetBoolean(ICET_GL_INITIALIZED, ICET_TRUE);
......@@ -51,9 +51,9 @@ IceTBoolean icetGLIsInitialized(void)
void icetGLSetReadBuffer(GLenum mode)
{
if (!icetGLIsInitialized()) {
icetRaiseError("IceT OpenGL layer not initialized."
" Call icetGLInitialize.",
ICET_INVALID_OPERATION);
icetRaiseError(ICET_INVALID_OPERATION,
"IceT OpenGL layer not initialized."
" Call icetGLInitialize.");
return;
}
......@@ -65,7 +65,7 @@ void icetGLSetReadBuffer(GLenum mode)
{
icetStateSetInteger(ICET_GL_READ_BUFFER, GL_BACK);
} else {
icetRaiseError("Invalid OpenGL read buffer.", ICET_INVALID_ENUM);
icetRaiseError(ICET_INVALID_ENUM, "Invalid OpenGL read buffer.");
}
}
......
......@@ -57,9 +57,9 @@
|| (_depth_format != icetSparseImageGetDepthFormat(BACK_SPARSE_IMAGE))
|| (_depth_format != icetSparseImageGetDepthFormat(DEST_SPARSE_IMAGE))
) {
icetRaiseError("Input buffers do not agree for compressed-compressed"
" composite.",
ICET_SANITY_CHECK_FAIL);
icetRaiseError(ICET_SANITY_CHECK_FAIL,
"Input buffers do not agree for compressed-compressed"
" composite.");
}
if (_composite_mode == ICET_COMPOSITE_MODE_Z_BUFFER) {
......@@ -158,15 +158,18 @@
#include "cc_composite_template_body.h"
#undef UNPACK_PIXEL
} else {
icetRaiseError("Encountered invalid color format.",
ICET_SANITY_CHECK_FAIL);
icetRaiseError(ICET_SANITY_CHECK_FAIL,
"Encountered invalid color format 0x%X.",
_color_format);
}
} else if (_depth_format == ICET_IMAGE_DEPTH_NONE) {
icetRaiseError("Cannot use Z buffer compositing operation with no"
" Z buffer.", ICET_INVALID_OPERATION);
icetRaiseError(ICET_INVALID_OPERATION,
"Cannot use Z buffer compositing operation with no"
" Z buffer.");
} else {
icetRaiseError("Encountered invalid depth format.",
ICET_SANITY_CHECK_FAIL);
icetRaiseError(ICET_SANITY_CHECK_FAIL,
"Encountered invalid depth format 0x%X.",
_depth_format);
}
} else if (_composite_mode == ICET_COMPOSITE_MODE_BLEND) {
/* Use alpha for active pixel and compositing. */
......@@ -214,20 +217,22 @@
#include "cc_composite_template_body.h"
#undef UNPACK_PIXEL
} else if (_color_format == ICET_IMAGE_COLOR_NONE) {
icetRaiseWarning("Compositing image with no data.",
ICET_INVALID_OPERATION);
icetRaiseWarning(ICET_INVALID_OPERATION,
"Compositing image with no data.");
icetClearSparseImage(DEST_SPARSE_IMAGE);
} else {
icetRaiseError("Encountered invalid color format.",
ICET_SANITY_CHECK_FAIL);
icetRaiseError(ICET_SANITY_CHECK_FAIL,
"Encountered invalid color format 0x%X.",
_color_format);
}
} else {
icetRaiseError("Cannot use blend composite with a depth buffer.",
ICET_INVALID_VALUE);
icetRaiseError(ICET_INVALID_VALUE,
"Cannot use blend composite with a depth buffer.");
}
} else {
icetRaiseError("Encountered invalid composite mode.",
ICET_SANITY_CHECK_FAIL);
icetRaiseError(ICET_SANITY_CHECK_FAIL,
"Encountered invalid composite mode 0x%X.",
_composite_mode);
}
}
......
......@@ -55,9 +55,9 @@
_num_pixels = icetSparseImageGetNumPixels(CCC_FRONT_COMPRESSED_IMAGE);
if (_num_pixels != icetSparseImageGetNumPixels(CCC_BACK_COMPRESSED_IMAGE)) {
icetRaiseError("Input buffers do not agree for compressed-compressed"
" composite.",
ICET_SANITY_CHECK_FAIL);
icetRaiseError(ICET_SANITY_CHECK_FAIL,
"Input buffers do not agree for compressed-compressed"
" composite.");
}
icetSparseImageSetDimensions(
CCC_DEST_COMPRESSED_IMAGE,
......@@ -161,7 +161,7 @@
}
if (_pixel != _num_pixels) {
icetRaiseError("Corrupt compressed image.", ICET_INVALID_VALUE);
icetRaiseError(ICET_INVALID_VALUE, "Corrupt compressed image.");
}
{
......
......@@ -24,8 +24,8 @@
#define icetCommCheckCount(count) \
if (count > 1073741824) { \
icetRaiseWarning("Encountered a ridiculously large message.", \
ICET_INVALID_VALUE); \
icetRaiseWarning(ICET_INVALID_VALUE, \
"Encountered a ridiculously large message."); \
}
IceTCommunicator icetCommDuplicate()
......
......@@ -88,29 +88,29 @@
if ( (icetSparseImageGetColorFormat(OUTPUT_SPARSE_IMAGE) != _color_format)
|| (icetSparseImageGetDepthFormat(OUTPUT_SPARSE_IMAGE) != _depth_format)
) {
icetRaiseError("Format of input and output to compress do not match.",
ICET_SANITY_CHECK_FAIL);
icetRaiseError(ICET_SANITY_CHECK_FAIL,
"Format of input and output to compress do not match.");
}
#ifdef PADDING
if ( icetSparseImageGetNumPixels(OUTPUT_SPARSE_IMAGE)
!= ( _pixel_count + (FULL_WIDTH)*(SPACE_TOP+SPACE_BOTTOM)
+ ((FULL_HEIGHT)-(SPACE_TOP+SPACE_BOTTOM))*(SPACE_LEFT+SPACE_RIGHT))
) {
icetRaiseError("Size of input and output to compress do not match.",
ICET_SANITY_CHECK_FAIL);
icetRaiseError(ICET_SANITY_CHECK_FAIL,
"Size of input and output to compress do not match.");
}
#else /*PADDING*/
if (icetSparseImageGetNumPixels(OUTPUT_SPARSE_IMAGE) != _pixel_count) {
icetRaiseError("Size of input and output to compress do not match.",
ICET_SANITY_CHECK_FAIL);
icetRaiseError(ICET_SANITY_CHECK_FAIL,
"Size of input and output to compress do not match.");
}
#endif /*PADDING*/
#ifdef REGION
if ( (REGION_OFFSET_X < 0) || (REGION_OFFSET_Y < 0)
|| (REGION_OFFSET_X+REGION_WIDTH > icetImageGetWidth(INPUT_IMAGE))
|| (REGION_OFFSET_Y+REGION_HEIGHT > icetImageGetHeight(INPUT_IMAGE)) ){
icetRaiseError("Size of input incompatible with region.",
ICET_SANITY_CHECK_FAIL);
icetRaiseError(ICET_SANITY_CHECK_FAIL,
"Size of input incompatible with region.");
}
#endif /*REGION*/
#endif /*DEBUG*/
......@@ -242,22 +242,25 @@
#endif
#include "compress_template_body.h"
} else {
icetRaiseError("Encountered invalid color format.",
ICET_SANITY_CHECK_FAIL);
icetRaiseError(ICET_SANITY_CHECK_FAIL,
"Encountered invalid color format 0x%X.",
_color_format);
}
} else if (_depth_format == ICET_IMAGE_DEPTH_NONE) {
icetRaiseError("Cannot use Z buffer compression with no"
" Z buffer.", ICET_INVALID_OPERATION);
icetRaiseError(ICET_INVALID_OPERATION,
"Cannot use Z buffer compression with no"
" Z buffer.");
} else {
icetRaiseError("Encountered invalid depth format.",
ICET_SANITY_CHECK_FAIL);
icetRaiseError(ICET_SANITY_CHECK_FAIL,
"Encountered invalid depth format 0x%X.",
_depth_format);
}
} else if (_composite_mode == ICET_COMPOSITE_MODE_BLEND) {
/* Use alpha for active pixel testing. */
if (_depth_format != ICET_IMAGE_DEPTH_NONE) {
icetRaiseWarning("Z buffer ignored during blend compress"
" operation. Output z buffer meaningless.",
ICET_INVALID_VALUE);
icetRaiseWarning(ICET_INVALID_VALUE,
"Z buffer ignored during blend compress"
" operation. Output z buffer meaningless.");
}
if (_color_format == ICET_IMAGE_COLOR_RGBA_UBYTE) {
const IceTUInt *_color;
......@@ -340,23 +343,25 @@
#include "compress_template_body.h"
} else if (_color_format == ICET_IMAGE_COLOR_NONE) {
IceTUInt *_out;
icetRaiseWarning("Compressing image with no data.",
ICET_INVALID_OPERATION);
icetRaiseWarning(ICET_INVALID_OPERATION,
"Compressing image with no data.");
_out = ICET_IMAGE_DATA(OUTPUT_SPARSE_IMAGE);
INACTIVE_RUN_LENGTH(_out) = _pixel_count;
ACTIVE_RUN_LENGTH(_out) = 0;
_out++;
icetSparseImageSetActualSize(OUTPUT_SPARSE_IMAGE, _out);
} else {
icetRaiseError("Encountered invalid color format.",
ICET_SANITY_CHECK_FAIL);
icetRaiseError(ICET_SANITY_CHECK_FAIL,
"Encountered invalid color format 0x%X.",
_color_format);
}
} else {
icetRaiseError("Encountered invalid composite mode.",
ICET_SANITY_CHECK_FAIL);
icetRaiseError(ICET_SANITY_CHECK_FAIL,
"Encountered invalid composite mode 0x%X.",
_composite_mode);
}
icetRaiseDebug1("Compression: %f%%\n",
icetRaiseDebug("Compression: %f%%\n",
100.0f - ( 100.0f*icetSparseImageGetCompressedBufferSize(OUTPUT_SPARSE_IMAGE)
/ icetImageBufferSizeType(_color_format, _depth_format,
icetSparseImageGetWidth(OUTPUT_SPARSE_IMAGE),
......
......@@ -177,10 +177,9 @@
* (CT_SPACE_LEFT+CT_SPACE_RIGHT) );
#endif /*CT_PADDING*/
if (_totalcount != (IceTSizeType)CT_PIXEL_COUNT) {
char msg[256];
sprintf(msg, "Total run lengths don't equal pixel count: %d != %d",
icetRaiseError(ICET_SANITY_CHECK_FAIL,
"Total run lengths don't equal pixel count: %d != %d",
(int)_totalcount, (int)(CT_PIXEL_COUNT));
icetRaiseError(msg, ICET_SANITY_CHECK_FAIL);
}
#endif /*DEBUG*/
......
......@@ -32,8 +32,8 @@ IceTContext icetCreateContext(IceTCommunicator comm)
IceTContext context = malloc(sizeof(struct IceTContextStruct));
if (context == NULL) {
icetRaiseError("Could not allocate memory for IceT context.",
ICET_OUT_OF_MEMORY);
icetRaiseError(ICET_OUT_OF_MEMORY,
"Could not allocate memory for IceT context.");
return NULL;
}
......@@ -101,7 +101,7 @@ IceTContext icetGetContext(void)
void icetSetContext(IceTContext context)
{
if (context && (context->magic_number != CONTEXT_MAGIC_NUMBER)) {
icetRaiseError("Invalid context.", ICET_INVALID_VALUE);
icetRaiseError(ICET_INVALID_VALUE, "Invalid context.");
return;
}
icet_current_context = context;
......
......@@ -76,28 +76,28 @@
_pixel_count = icetSparseImageGetNumPixels(INPUT_SPARSE_IMAGE);
if (_color_format != icetImageGetColorFormat(OUTPUT_IMAGE)) {
icetRaiseError("Input/output buffers have different color formats.",
ICET_SANITY_CHECK_FAIL);
icetRaiseError(ICET_SANITY_CHECK_FAIL,
"Input/output buffers have different color formats.");
}
if (_depth_format != icetImageGetDepthFormat(OUTPUT_IMAGE)) {
icetRaiseError("Input/output buffers have different depth formats.",
ICET_SANITY_CHECK_FAIL);
icetRaiseError(ICET_SANITY_CHECK_FAIL,
"Input/output buffers have different depth formats.");
}
#ifdef PIXEL_COUNT
if (_pixel_count != PIXEL_COUNT) {
icetRaiseError("Unexpected input pixel count.",
ICET_SANITY_CHECK_FAIL);
icetRaiseError(ICET_SANITY_CHECK_FAIL,
"Unexpected input pixel count.");
}
#else
if (_pixel_count != icetImageGetNumPixels(OUTPUT_IMAGE)) {
icetRaiseError("Unexpected input pixel count.",
ICET_SANITY_CHECK_FAIL);
icetRaiseError(ICET_SANITY_CHECK_FAIL,
"Unexpected input pixel count.");
}
#endif
#ifdef OFFSET
if (_pixel_count > icetImageGetNumPixels(OUTPUT_IMAGE) - OFFSET) {
icetRaiseError("Offset pixels outside range of output image.",
ICET_SANITY_CHECK_FAIL);
icetRaiseError(ICET_SANITY_CHECK_FAIL,
"Offset pixels outside range of output image.");
}
#endif
......@@ -235,22 +235,25 @@
#include "decompress_template_body.h"
#undef COPY_PIXEL
} else {
icetRaiseError("Encountered invalid color format.",
ICET_SANITY_CHECK_FAIL);
icetRaiseError(ICET_SANITY_CHECK_FAIL,
"Encountered invalid color format 0x%X.",
_color_format);
}
} else if (_depth_format == ICET_IMAGE_DEPTH_NONE) {
icetRaiseError("Cannot use Z buffer compositing operation with no"
" Z buffer.", ICET_INVALID_OPERATION);
icetRaiseError(ICET_INVALID_OPERATION,
"Cannot use Z buffer compositing operation with no"
" Z buffer.");
} else {
icetRaiseError("Encountered invalid depth format.",
ICET_SANITY_CHECK_FAIL);
icetRaiseError(ICET_SANITY_CHECK_FAIL,
"Encountered invalid depth format 0x%X.",
_depth_format);
}
} else if (_composite_mode == ICET_COMPOSITE_MODE_BLEND) {
/* Use alpha for active pixel and compositing. */
if (_depth_format != ICET_IMAGE_DEPTH_NONE) {
icetRaiseWarning("Z buffer ignored during blend composite"
" operation. Output z buffer meaningless.",
ICET_INVALID_VALUE);
icetRaiseWarning(ICET_INVALID_VALUE,
"Z buffer ignored during blend composite"
" operation. Output z buffer meaningless.");
}
if (_color_format == ICET_IMAGE_COLOR_RGBA_UBYTE) {
IceTUInt *_color;
......@@ -345,15 +348,15 @@
#include "decompress_template_body.h"
#undef COPY_PIXEL
} else if (_color_format == ICET_IMAGE_COLOR_NONE) {
icetRaiseWarning("Decompressing image with no data.",
ICET_INVALID_OPERATION);
icetRaiseWarning(ICET_INVALID_OPERATION,
"Decompressing image with no data.");
} else {
icetRaiseError("Encountered invalid color format.",
ICET_SANITY_CHECK_FAIL);
icetRaiseError(ICET_SANITY_CHECK_FAIL,
"Encountered invalid color format.");
}
} else {
icetRaiseError("Encountered invalid composite mode.",
ICET_SANITY_CHECK_FAIL);
icetRaiseError(ICET_SANITY_CHECK_FAIL,
"Encountered invalid composite mode.");
}
#ifdef TIME_DECOMPRESSION
......
......@@ -55,7 +55,7 @@
_rl = INACTIVE_RUN_LENGTH(_runlengths);
_p += _rl;
if (_p > _pixels) {
icetRaiseError("Corrupt compressed image.", ICET_INVALID_VALUE);
icetRaiseError(ICET_INVALID_VALUE, "Corrupt compressed image.");
break;
}
DT_INCREMENT_INACTIVE_PIXELS(_rl);
......@@ -64,7 +64,7 @@
_rl = ACTIVE_RUN_LENGTH(_runlengths);
_p += _rl;
if (_p > _pixels) {
icetRaiseError("Corrupt compressed image.", ICET_INVALID_VALUE);
icetRaiseError(ICET_INVALID_VALUE, "Corrupt compressed image.");
break;
}
for (_i = 0; _i < _rl; _i++) {
......
......@@ -16,6 +16,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <signal.h>
......@@ -27,20 +28,26 @@
static IceTEnum currentError = ICET_NO_ERROR;
static IceTEnum currentLevel;
void icetRaiseDiagnostic(const char *msg, IceTEnum type,
IceTBitField level, const char *file, int line)
void icetRaiseDiagnostic(IceTEnum type,
IceTBitField level,
const char *file,
int line,
const char *format,
...)
{
#define ICET_MESSAGE_SIZE 1024
static int raisingDiagnostic = 0;
IceTBitField diagLevel;
IceTInt tmpInt;
static char full_message[1024];
char *m;
static char full_message[ICET_MESSAGE_SIZE+1];
IceTSizeType offset;
int rank;
va_list format_args;
#define FINISH raisingDiagnostic = 0; return
if (raisingDiagnostic) {
printf("PANIC: diagnostic raised while rasing diagnostic!\n");
printf("PANIC:%s:%d: diagnostic raised while rasing diagnostic!\n",
file, line);
icetStateDump();
#ifdef DEBUG
icetDebugBreak();
......@@ -48,7 +55,8 @@ void icetRaiseDiagnostic(const char *msg, IceTEnum type,
return;
}
if (icetGetState() == NULL) {
printf("PANIC: diagnostic raised when no context was current!\n");
printf("PANIC:%s:%d: diagnostic raised when no context was current!\n",
file, line);
#ifdef DEBUG
icetDebugBreak();
#endif
......@@ -56,13 +64,20 @@ void icetRaiseDiagnostic(const char *msg, IceTEnum type,
}
raisingDiagnostic = 1;
full_message[0] = '\0';
m = full_message;
offset = 0;
#define ADD_TO_MESSAGE(...) \
offset += sprintf(full_message + offset, __VA_ARGS__); \
if (offset > ICET_MESSAGE_SIZE) { \
printf("PANIC:%s:%d: Diagnostic message too large!\n", file, line); \
icetStateDump(); \
return; \
}
if ((currentError == ICET_NO_ERROR) || (level < currentLevel)) {
currentError = type;
currentLevel = level;
}
icetGetIntegerv(ICET_DIAGNOSTIC_LEVEL, &tmpInt);
diagLevel = tmpInt;
diagLevel = icetUnsafeStateGetInteger(ICET_DIAGNOSTIC_LEVEL)[0];
if ((diagLevel & level) != level) {
/* Don't do anything if we are not reporting the raised diagnostic. */
FINISH;
......@@ -71,39 +86,38 @@ void icetRaiseDiagnostic(const char *msg, IceTEnum type,
rank = icetCommRank();
if ((diagLevel & ICET_DIAG_ALL_NODES) != 0) {
/* Reporting on all nodes. */
sprintf(m, "ICET,%d:", rank);
ADD_TO_MESSAGE("ICET,%d:", rank);
} else if (rank == 0) {
/* Rank 0 is lone reporter. */
strcpy(m, "ICET:");
ADD_TO_MESSAGE("ICET:");
} else {
/* Not reporting because not rank 0. */
FINISH;
}
m += strlen(m);
/* Add description of diagnostic type. */
switch (level & 0xFF) {
case ICET_DIAG_ERRORS:
strcpy(m, "ERROR:");
ADD_TO_MESSAGE("ERROR:");
break;
case ICET_DIAG_WARNINGS:
strcpy(m, "WARNING:");
ADD_TO_MESSAGE("WARNING:");
break;
case ICET_DIAG_DEBUG:
strcpy(m, "DEBUG:");
ADD_TO_MESSAGE("DEBUG:");
break;
}
m += strlen(m);
#ifdef DEBUG
sprintf(m, "%s:%d:", file, line);
m += strlen(m);
ADD_TO_MESSAGE("%s:%d:", file, line);
#else
/* shut up warnings */
(void)file;
(void)line;
#endif
sprintf(m, " %s\n", msg);
printf("%s", full_message);
ADD_TO_MESSAGE(" %s\n", format);
va_start(format_args, format);
vprintf(full_message, format_args);
va_end(format_args);
fflush(stdout);
#ifdef DEBUG
......
......@@ -39,7 +39,7 @@ void icetStrategy(IceTEnum strategy)
icetStateSetBoolean(ICET_STRATEGY_SUPPORTS_ORDERING,
icetStrategySupportsOrdering(strategy));
} else {
icetRaiseError("Invalid strategy.", ICET_INVALID_ENUM);
icetRaiseError(ICET_INVALID_ENUM, "Invalid strategy.");
}
}
......@@ -51,8 +51,9 @@ const char *icetGetStrategyName(void)
if (strategy != ICET_STRATEGY_UNDEFINED) {
return icetStrategyNameFromEnum(strategy);
} else {
icetRaiseError("No strategy set. Use icetStrategy to set the strategy.",
ICET_INVALID_ENUM);
icetRaiseError(
ICET_INVALID_ENUM,
"No strategy set. Use icetStrategy to set the strategy.");
return NULL;
}
}
......@@ -62,7 +63,7 @@ void icetSingleImageStrategy(IceTEnum strategy)
if (icetSingleImageStrategyValid(strategy)) {
icetStateSetInteger(ICET_SINGLE_IMAGE_STRATEGY, strategy);
} else {
icetRaiseError("Invalid single image strategy.", ICET_INVALID_ENUM);
icetRaiseError(ICET_INVALID_ENUM, "Invalid single image strategy.");
}
}
......@@ -78,7 +79,7 @@ void icetCompositeMode(IceTEnum mode)