2019-05-12 21:17:24 -05:00
// 12 may 2019
# include "uipriv.h"
2019-05-26 14:41:22 -05:00
# include "testhooks.h"
2019-05-12 21:17:24 -05:00
2019-05-13 20:30:18 -05:00
# define internalErrorPrefix "libui internal error"
// TODO add debugging advice?
# define internalErrorSuffix "This likely means there is a bug in libui itself. Contact the libui authors."
void uiprivInternalError ( const char * fmt , . . . )
{
va_list ap ;
2020-02-09 19:49:47 -06:00
char buf [ 256 ] ;
2019-05-13 20:30:18 -05:00
int n ;
va_start ( ap , fmt ) ;
2020-02-09 19:49:47 -06:00
n = uiprivVsnprintf ( buf , 256 , fmt , ap ) ;
2019-05-13 20:30:18 -05:00
va_end ( ap ) ;
if ( n < 0 )
uiprivReportError ( internalErrorPrefix , " internal error string has encoding error " , internalErrorSuffix , true ) ;
2020-02-09 19:49:47 -06:00
if ( n > = 256 )
2019-05-13 20:30:18 -05:00
uiprivReportError ( internalErrorPrefix , " internal error string too long " , internalErrorSuffix , true ) ;
uiprivReportError ( internalErrorPrefix , buf , internalErrorSuffix , true ) ;
}
# define programmerErrorPrefix "libui programmer error"
// TODO add debugging advice?
# define programmerErrorSuffix "This likely means you are using libui incorrectly. Check your source code and try again. If you have received this warning in error, contact the libui authors."
2019-06-09 12:49:53 -05:00
static uiprivTestHookReportProgrammerErrorFunc reportProgrammerErrorTestHook = NULL ;
static void * reportProgrammerErrorTestHookData = NULL ;
2019-05-26 14:41:22 -05:00
2019-06-09 12:49:53 -05:00
void uiprivTestHookReportProgrammerError ( uiprivTestHookReportProgrammerErrorFunc f , void * data )
2019-05-26 14:41:22 -05:00
{
reportProgrammerErrorTestHook = f ;
2019-06-09 12:49:53 -05:00
reportProgrammerErrorTestHookData = data ;
2019-05-26 14:41:22 -05:00
}
2019-06-02 01:23:12 -05:00
void uiprivProgrammerError ( const char * fmt , . . . )
2019-05-12 21:17:24 -05:00
{
va_list ap ;
2019-06-02 01:23:12 -05:00
int n ;
2020-02-09 19:49:47 -06:00
char buf [ 256 ] ;
2019-05-12 21:17:24 -05:00
2019-06-02 01:23:12 -05:00
va_start ( ap , fmt ) ;
2020-02-09 19:49:47 -06:00
n = uiprivVsnprintf ( buf , 256 , fmt , ap ) ;
2019-06-02 01:23:12 -05:00
if ( n < 0 )
uiprivInternalError ( " programmer error has encoding error " ) ;
2020-02-09 19:49:47 -06:00
if ( n > = 256 )
2019-06-02 01:23:12 -05:00
uiprivInternalError ( " programmer error string too long (%d) " , n ) ;
2019-05-12 21:17:24 -05:00
va_end ( ap ) ;
2019-06-09 12:49:53 -05:00
if ( reportProgrammerErrorTestHook ! = NULL ) {
( * reportProgrammerErrorTestHook ) ( buf , reportProgrammerErrorTestHookData ) ;
return ;
}
uiprivReportError ( programmerErrorPrefix , buf , programmerErrorSuffix , false ) ;
2019-05-12 21:17:24 -05:00
}