2006-03-20 16:43:15 +00:00
/*
2014-06-01 17:55:23 +00:00
* Portions of this file are copyright Rebirth contributors and licensed as
* described in COPYING . txt .
* Portions of this file are copyright Parallax Software and licensed
* according to the Parallax license below .
* See COPYING . txt for license details .
2006-03-20 16:43:15 +00:00
THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
SOFTWARE CORPORATION ( " PARALLAX " ) . PARALLAX , IN DISTRIBUTING THE CODE TO
END - USERS , AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN , GRANTS A
ROYALTY - FREE , PERPETUAL LICENSE TO SUCH END - USERS FOR USE BY SUCH END - USERS
IN USING , DISPLAYING , AND CREATING DERIVATIVE WORKS THEREOF , SO LONG AS
SUCH USE , DISPLAY OR CREATION IS FOR NON - COMMERCIAL , ROYALTY OR REVENUE
FREE PURPOSES . IN NO EVENT SHALL THE END - USER USE THE COMPUTER CODE
CONTAINED HEREIN FOR REVENUE - BEARING PURPOSES . THE END - USER UNDERSTANDS
2013-02-24 02:39:48 +00:00
AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE .
2006-03-20 16:43:15 +00:00
COPYRIGHT 1993 - 1998 PARALLAX SOFTWARE CORPORATION . ALL RIGHTS RESERVED .
*/
2008-01-23 17:25:09 +00:00
2006-03-20 16:43:15 +00:00
/*
*
* Header for error handling / printing / exiting code
*
*/
2014-12-07 23:43:51 +00:00
# pragma once
2008-01-23 17:25:09 +00:00
2015-10-09 02:46:11 +00:00
# include <cstddef>
2008-01-23 17:25:09 +00:00
# include <stdio.h>
2013-06-27 02:35:22 +00:00
# include "dxxsconf.h"
2016-03-19 19:08:10 +00:00
# include "dsx-ns.h"
2013-06-23 02:28:43 +00:00
# include <assert.h>
2013-12-08 23:37:40 +00:00
# include "fmtcheck.h"
2008-01-23 17:25:09 +00:00
2012-11-11 22:12:51 +00:00
# ifdef __cplusplus
2006-03-20 16:43:15 +00:00
# ifdef __GNUC__
# define __noreturn __attribute__ ((noreturn))
# else
# define __noreturn
# endif
2015-12-13 18:00:49 +00:00
namespace dcx {
2015-12-05 22:57:24 +00:00
2013-06-23 21:18:48 +00:00
int error_init ( void ( * func ) ( const char * ) ) ; //init error system, returns 0=ok
2013-12-08 23:37:40 +00:00
void Warning_puts ( const char * str ) __attribute_nonnull ( ) ;
2013-06-27 02:35:22 +00:00
void Warning ( const char * fmt , . . . ) __attribute_format_printf ( 1 , 2 ) ; //print out warning message to user
2013-12-08 23:37:40 +00:00
# define Warning(F,...) dxx_call_printf_checked(Warning,Warning_puts,(),(F),##__VA_ARGS__)
2013-06-08 22:24:17 +00:00
void set_warn_func ( void ( * f ) ( const char * s ) ) ; //specifies the function to call with warning messages
2013-06-08 23:12:44 +00:00
void clear_warn_func ( ) ; //say this function no longer valid
2015-10-11 22:21:00 +00:00
__noreturn
__attribute_nonnull ( )
void Error_puts ( const char * file , unsigned line , const char * func , const char * str ) ;
# define Error_puts(F) Error_puts(__FILE__, __LINE__, __func__, F)
__noreturn
__attribute_format_printf ( 4 , 5 )
__attribute_nonnull ( )
void Error ( const char * file , unsigned line , const char * func , const char * fmt , . . . ) ; //exit with error code=1, print message
# define Error(F,...) dxx_call_printf_checked(Error,(Error_puts),(__FILE__, __LINE__, __func__),(F),##__VA_ARGS__)
2015-10-09 02:46:11 +00:00
__noreturn
void UserError_puts ( const char * str , std : : size_t ) ;
template < std : : size_t len >
__noreturn
static inline void UserError_puts ( const char ( & str ) [ len ] )
{
UserError_puts ( str , len - 1 ) ;
}
2015-06-16 03:15:40 +00:00
void UserError ( const char * fmt , . . . ) __noreturn __attribute_format_printf ( 1 , 2 ) ;
2015-12-23 03:28:17 +00:00
}
2016-04-03 17:50:42 +00:00
# define DXX_STRINGIZE_FL2(F,L,S) F ":" #L ": " S
# define DXX_STRINGIZE_FL(F,L,S) DXX_STRINGIZE_FL2(F, L, S)
# define UserError(F,...) dxx_call_printf_checked(UserError,(UserError_puts),(),DXX_STRINGIZE_FL(__FILE__, __LINE__, F),##__VA_ARGS__)
2013-06-23 02:28:43 +00:00
# define Assert assert
2006-03-20 16:43:15 +00:00
2016-10-17 03:49:32 +00:00
# define LevelError(F,...) con_printf(CON_URGENT, DXX_STRINGIZE_FL(__FILE__, __LINE__, F " Please report this to the level author, not to the Rebirth maintainers."), ##__VA_ARGS__)
2014-12-07 23:43:51 +00:00
/* Compatibility with x86-specific name */
# define Int3() d_debugbreak()
# ifndef NDEBUG //macros for debugging
2014-12-24 03:34:33 +00:00
# define DXX_ENABLE_DEBUGBREAK_TRAP
2014-12-07 23:43:51 +00:00
# endif
2006-03-20 16:43:15 +00:00
2014-12-07 23:43:51 +00:00
/* Allow macro override */
2014-12-08 03:01:55 +00:00
2014-12-24 03:34:33 +00:00
# if defined(DXX_ENABLE_DEBUGBREAK_TRAP) && !defined(DXX_DEBUGBREAK_TRAP)
2006-03-20 16:43:15 +00:00
2014-12-07 23:43:51 +00:00
# if defined __clang__
/* Must be first, since clang also defines __GNUC__ */
2014-12-24 03:34:33 +00:00
# define DXX_DEBUGBREAK_TRAP() __builtin_debugtrap()
2014-12-07 23:43:51 +00:00
# elif defined __GNUC__
# if defined(__i386__) || defined(__amd64__)
2014-12-24 03:34:33 +00:00
# define DXX_DEBUGBREAK_TRAP() __asm__ __volatile__("int3" ::: "cc", "memory")
2014-12-07 23:43:51 +00:00
# endif
# elif defined _MSC_VER
2014-12-24 03:34:33 +00:00
# define DXX_DEBUGBREAK_TRAP() __debugbreak()
# endif
# ifndef DXX_DEBUGBREAK_TRAP
# if defined __unix__
/* for raise */
# include <signal.h>
# define DXX_DEBUGBREAK_TRAP() raise(SIGTRAP)
# elif defined __GNUC__
/* May terminate execution */
# define DXX_DEBUGBREAK_TRAP() __builtin_trap()
# endif
2006-03-20 16:43:15 +00:00
# endif
2008-01-23 17:25:09 +00:00
2014-12-07 23:43:51 +00:00
# endif
2014-12-24 03:34:33 +00:00
2015-12-23 03:28:17 +00:00
namespace dcx {
2014-12-24 03:34:33 +00:00
// Encourage optimizer to treat d_debugbreak paths as unlikely
__attribute_cold
// Requested by btb to force Xcode to stay in the calling function
2015-01-18 01:58:33 +00:00
__attribute_always_inline ( )
2014-12-24 03:34:33 +00:00
static inline void d_debugbreak ( )
{
/* Allow explicit activation in NDEBUG builds */
# ifdef DXX_DEBUGBREAK_TRAP
DXX_DEBUGBREAK_TRAP ( ) ;
2012-11-11 22:12:51 +00:00
# endif
2014-12-24 03:34:33 +00:00
}
2015-12-05 22:57:24 +00:00
}
2014-12-07 23:43:51 +00:00
# endif