Make both MSVC and GCC use a very similar define for ASSERT.
I am afraid that I reverted the changes made by Per. Will try to recover them tomorrow. git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@590 4a71c877-e1ca-e34f-864e-861f7616d084master
parent
3210bebd6b
commit
a026b6118d
|
@ -28,42 +28,6 @@ static const char *code_part_names[] = {
|
|||
"net", "memory", "error", "never", "script", "last"
|
||||
};
|
||||
|
||||
static int msvc_line = -1;
|
||||
static char msvc_file[250];
|
||||
|
||||
/* Protos */
|
||||
static void real_debug(enum code_part part, const char *str, va_list ap);
|
||||
|
||||
/**********************************************************************
|
||||
MSVC hacks.
|
||||
**********************************************************************/
|
||||
void debug_msvc(const char *str, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, str);
|
||||
real_debug(LOG_NEVER, str, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
void dbg_position(const char *file, int line)
|
||||
{
|
||||
msvc_line = line;
|
||||
strncpy(msvc_file, file, 250);
|
||||
}
|
||||
void dbg_assert(BOOL condition, const char *str, ...)
|
||||
{
|
||||
if (!(condition)) {
|
||||
va_list ap;
|
||||
va_start(ap, str);
|
||||
debug(LOG_ERROR, "Error in Warzone: file %s, line %d",
|
||||
msvc_file, msvc_line);
|
||||
real_debug(LOG_ERROR, str, ap);
|
||||
va_end(ap);
|
||||
#ifdef DEBUG
|
||||
assert(condition);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/**********************************************************************
|
||||
cat_snprintf is like a combination of snprintf and strlcat;
|
||||
it does snprintf to the end of an existing string.
|
||||
|
@ -212,12 +176,6 @@ static void debug_out(const char *buf)
|
|||
void debug(enum code_part part, const char *str, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, str);
|
||||
real_debug(part, str, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
static void real_debug(enum code_part part, const char *str, va_list ap)
|
||||
{
|
||||
static char bufbuf[2][MAX_LEN_LOG_LINE];
|
||||
char buf[MAX_LEN_LOG_LINE+MAX_LEN_DEBUG_PART];
|
||||
static BOOL bufbuf1 = FALSE;
|
||||
|
@ -230,9 +188,11 @@ static void real_debug(enum code_part part, const char *str, va_list ap)
|
|||
return;
|
||||
}
|
||||
|
||||
va_start(ap, str);
|
||||
// FIXME This is buggy. Eg the OpenAL extensions string is corrupted after about 160 chars.
|
||||
// That does not happen if vsprintf() is used instead. But then then string is corrupted after it's end.
|
||||
vsnprintf( bufbuf1 ? bufbuf[1] : bufbuf[0], MAX_LEN_LOG_LINE, str, ap );
|
||||
va_end(ap);
|
||||
|
||||
if (0 == strncmp(bufbuf[0], bufbuf[1], MAX_LEN_LOG_LINE - 1)) {
|
||||
repeated++;
|
||||
|
|
|
@ -34,15 +34,10 @@
|
|||
#define DBPRINTF(x) _db_debug x
|
||||
#define _db_debug(...) debug(LOG_NEVER, __VA_ARGS__)
|
||||
#else
|
||||
#define DBMB(x) debug_msvc(x)
|
||||
#define DBPRINTF(x) debug_msvc(x)
|
||||
#define DBMB(x)
|
||||
#define DBPRINTF(x)
|
||||
#endif
|
||||
|
||||
/* Special MSVC hacks */
|
||||
void debug_msvc(const char *str, ...);
|
||||
void dbg_position(const char *file, int line);
|
||||
void dbg_assert(BOOL condition, const char *str, ...);
|
||||
|
||||
/*
|
||||
*
|
||||
* ASSERT
|
||||
|
@ -52,31 +47,27 @@ void dbg_assert(BOOL condition, const char *str, ...);
|
|||
*
|
||||
* Arguments: ASSERT((condition, "Format string with variables: %d, %d", var1, var2));
|
||||
*/
|
||||
# define ASSERT(x) wz_assert x
|
||||
#ifdef _MSC_VER
|
||||
// MSVC doesn't understand __VAR_ARGS__ macros
|
||||
# define ASSERT(x) do { dbg_position(__FILE__, __LINE__); dbg_assert(x); } while(0)
|
||||
# define wz_assert(x, ...) \
|
||||
do { \
|
||||
if (!(x)) { \
|
||||
debug( LOG_ERROR, "Assert in Warzone: file %s, line %d", \
|
||||
__FILE__, __LINE__ ); \
|
||||
assert(x); \
|
||||
} \
|
||||
} while (FALSE)
|
||||
#else
|
||||
# define ASSERT(x) wz_assert x
|
||||
# ifdef DEBUG
|
||||
# define wz_assert(x, ...) \
|
||||
do { \
|
||||
if (!(x)) { \
|
||||
debug(LOG_ERROR, "Error in Warzone: file %s, function %s, line %d", \
|
||||
__FILE__, __FUNCTION__, __LINE__); \
|
||||
debug(LOG_ERROR, __VA_ARGS__); \
|
||||
assert(x); \
|
||||
} \
|
||||
# define wz_assert(x, ...) \
|
||||
do { \
|
||||
if (!(x)) { \
|
||||
debug( LOG_ERROR, "Assert in Warzone: file %s, function %s, line %d", \
|
||||
__FILE__, __FUNCTION__, __LINE__ ); \
|
||||
debug( LOG_ERROR, __VA_ARGS__ ); \
|
||||
assert(x); \
|
||||
} \
|
||||
} while (FALSE)
|
||||
# else
|
||||
# define wz_assert(x, ...) \
|
||||
do { \
|
||||
if (!(x)) { \
|
||||
debug(LOG_ERROR, "Error in Warzone: file %s, function %s, line %d", \
|
||||
__FILE__, __FUNCTION__, __LINE__); \
|
||||
debug(LOG_ERROR, __VA_ARGS__); \
|
||||
} \
|
||||
} while (FALSE)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
|
@ -97,7 +88,7 @@ do { \
|
|||
abort(); \
|
||||
} while (FALSE);
|
||||
#else
|
||||
#define DBERROR(x) do { debug_msvc(x); abort(); } while(0)
|
||||
#define DBERROR(x)
|
||||
#endif
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue