Use a thread-safe static inline function for printing
This commit is contained in:
parent
0fac1e9115
commit
1454c46b5f
@ -37,13 +37,6 @@
|
|||||||
#include "bs2b.h"
|
#include "bs2b.h"
|
||||||
#include "alu.h"
|
#include "alu.h"
|
||||||
|
|
||||||
///////////////////////////////////////////////////////
|
|
||||||
// DEBUG INFORMATION
|
|
||||||
|
|
||||||
char _alDebug[256];
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
|
|
||||||
#define EmptyFuncs { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }
|
#define EmptyFuncs { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }
|
||||||
static struct {
|
static struct {
|
||||||
|
@ -168,6 +168,16 @@ IF(NOT HAVE_SNPRINTF)
|
|||||||
ADD_DEFINITIONS(-Dsnprintf=_snprintf)
|
ADD_DEFINITIONS(-Dsnprintf=_snprintf)
|
||||||
ENDIF()
|
ENDIF()
|
||||||
|
|
||||||
|
CHECK_FUNCTION_EXISTS(vsnprintf HAVE_VSNPRINTF)
|
||||||
|
IF(NOT HAVE_VSNPRINTF)
|
||||||
|
CHECK_FUNCTION_EXISTS(_vsnprintf HAVE__VSNPRINTF)
|
||||||
|
IF(NOT HAVE__VSNPRINTF)
|
||||||
|
MESSAGE(FATAL_ERROR "No vsnprintf function found, please report!")
|
||||||
|
ENDIF()
|
||||||
|
|
||||||
|
ADD_DEFINITIONS(-Dvsnprintf=_vsnprintf)
|
||||||
|
ENDIF()
|
||||||
|
|
||||||
CHECK_SYMBOL_EXISTS(isnan math.h HAVE_ISNAN)
|
CHECK_SYMBOL_EXISTS(isnan math.h HAVE_ISNAN)
|
||||||
IF(NOT HAVE_ISNAN)
|
IF(NOT HAVE_ISNAN)
|
||||||
CHECK_FUNCTION_EXISTS(_isnan HAVE__ISNAN)
|
CHECK_FUNCTION_EXISTS(_isnan HAVE__ISNAN)
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
#ifdef HAVE_FENV_H
|
#ifdef HAVE_FENV_H
|
||||||
#include <fenv.h>
|
#include <fenv.h>
|
||||||
@ -107,19 +108,30 @@ static inline void Sleep(ALuint t)
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern char _alDebug[256];
|
static __inline void al_print(const char *fname, unsigned int line, const char *fmt, ...)
|
||||||
|
{
|
||||||
|
const char *fn;
|
||||||
|
char str[256];
|
||||||
|
int i;
|
||||||
|
|
||||||
#define AL_PRINT(...) do { \
|
fn = strrchr(fname, '/');
|
||||||
int _al_print_i; \
|
if(!fn) fn = strrchr(fname, '\\');;
|
||||||
const char *_al_print_fn = strrchr(__FILE__, '/'); \
|
if(!fn) fn = fname;
|
||||||
if(!_al_print_fn) _al_print_fn = __FILE__; \
|
else fn += 1;
|
||||||
else _al_print_fn += 1; \
|
|
||||||
_al_print_i = snprintf(_alDebug, sizeof(_alDebug), "AL lib: %s:%d: ", _al_print_fn, __LINE__); \
|
i = snprintf(str, sizeof(str), "AL lib: %s:%d: ", fn, line);
|
||||||
if(_al_print_i < (int)sizeof(_alDebug) && _al_print_i > 0) \
|
if(i < (int)sizeof(str) && i > 0)
|
||||||
snprintf(_alDebug+_al_print_i, sizeof(_alDebug)-_al_print_i, __VA_ARGS__); \
|
{
|
||||||
_alDebug[sizeof(_alDebug)-1] = 0; \
|
va_list ap;
|
||||||
fprintf(stderr, "%s", _alDebug); \
|
va_start(ap, fmt);
|
||||||
} while(0)
|
vsnprintf(str+i, sizeof(str)-i, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
}
|
||||||
|
str[sizeof(str)-1] = 0;
|
||||||
|
|
||||||
|
fprintf(stderr, "%s", str);
|
||||||
|
}
|
||||||
|
#define AL_PRINT(...) al_print(__FILE__, __LINE__, __VA_ARGS__)
|
||||||
|
|
||||||
|
|
||||||
#define SWMIXER_OUTPUT_RATE 44100
|
#define SWMIXER_OUTPUT_RATE 44100
|
||||||
|
Loading…
x
Reference in New Issue
Block a user