Add VGM_LOG/ASSERT_ONCE macro for useful-but-repetitive error logging

This commit is contained in:
bnnm 2017-11-23 23:46:33 +01:00
parent e1bb468bd5
commit 5c4351aa86
2 changed files with 9 additions and 18 deletions

View File

@ -22,9 +22,6 @@ typedef struct {
uint8_t * buffer; /* data buffer */
size_t buffersize; /* max buffer size */
size_t filesize; /* cached file size (max offset) */
#ifdef VGM_DEBUG_OUTPUT
int error_notified;
#endif
#ifdef PROFILE_STREAMFILE
size_t bytes_read;
int error_count;
@ -67,13 +64,7 @@ static size_t read_the_rest(uint8_t * dest, off_t offset, size_t length, STDIOST
/* request outside file: ignore to avoid seek/read */
if (offset > streamfile->filesize) {
streamfile->offset = streamfile->filesize;
#ifdef VGM_DEBUG_OUTPUT
if (!streamfile->error_notified) {
VGM_LOG("ERROR: reading over filesize 0x%x @ 0x%lx + 0x%x (buggy meta?)\n", streamfile->filesize, offset, length);
streamfile->error_notified = 1;
}
#endif
VGM_LOG_ONCE("ERROR: reading over filesize 0x%x @ 0x%lx + 0x%x (buggy meta?)\n", streamfile->filesize, offset, length);
#if STREAMFILE_IGNORE_EOF
memset(dest,0,length); /* dest is already shifted */
@ -143,13 +134,7 @@ static size_t read_stdio(STDIOSTREAMFILE *streamfile,uint8_t * dest, off_t offse
/* request outside file: ignore to avoid seek/read in read_the_rest() */
if (offset > streamfile->filesize) {
streamfile->offset = streamfile->filesize;
#ifdef VGM_DEBUG_OUTPUT
if (!streamfile->error_notified) {
VGM_LOG("ERROR: offset over filesize 0x%x @ 0x%lx + 0x%x (buggy meta?)\n", streamfile->filesize, offset, length);
streamfile->error_notified = 1;
}
#endif
VGM_LOG_ONCE("ERROR: offset over filesize 0x%x @ 0x%lx + 0x%x (buggy meta?)\n", streamfile->filesize, offset, length);
#if STREAMFILE_IGNORE_EOF
memset(dest,0,length);

View File

@ -78,15 +78,19 @@ void concatn(int length, char * dst, const char * src);
/* Simple stdout logging for debugging and regression testing purposes.
* Needs C99 variadic macros. */
* Needs C99 variadic macros, uses do..while to force ; as statement */
#ifdef VGM_DEBUG_OUTPUT
/* equivalent to printf when condition is true */
#define VGM_ASSERT(condition, ...) \
do { if (condition) printf(__VA_ARGS__); } while (0)
#define VGM_ASSERT_ONCE(condition, ...) \
do { static int written; if (!written) { if (condition) printf(__VA_ARGS__); written = 1; } } while (0)
/* equivalent to printf */
#define VGM_LOG(...) \
do { printf(__VA_ARGS__); } while (0)
#define VGM_LOG_ONCE(...) \
do { static int written; if (!written) { printf(__VA_ARGS__); written = 1; } } while (0)
/* prints file/line/func */
#define VGM_LOGF() \
do { printf("%s:%i '%s'\n", __FILE__, __LINE__, __func__); } while (0)
@ -108,10 +112,12 @@ void concatn(int length, char * dst, const char * src);
#define VGM_ASSERT(condition, ...) /* nothing */
#define VGM_LOG(...) /* nothing */
#define VGM_LOG_ONCE(...) /* nothing */
#define VGM_LOGF() /* nothing */
#define VGM_LOGT() /* nothing */
#define VGM_LOGB(buf, buf_size, bytes_per_line) /* nothing */
#endif/*VGM_DEBUG_OUTPUT*/
#endif