| 1 | |
| 2 | // By default, #included at beginning of library source files |
| 3 | |
| 4 | // Copyright (C) 2005 Shay Green. |
| 5 | |
| 6 | #ifndef BLARGG_SOURCE_H |
| 7 | #define BLARGG_SOURCE_H |
| 8 | |
| 9 | // If debugging is enabled, abort program if expr is false. Meant for checking |
| 10 | // internal state and consistency. A failed assertion indicates a bug in the module. |
| 11 | // void assert( bool expr ); |
| 12 | #include <assert.h> |
| 13 | |
| 14 | // If debugging is enabled and expr is false, abort program. Meant for checking |
| 15 | // caller-supplied parameters and operations that are outside the control of the |
| 16 | // module. A failed requirement indicates a bug outside the module. |
| 17 | // void require( bool expr ); |
| 18 | #undef require |
| 19 | #define require( expr ) assert(( "unmet requirement", expr )) |
| 20 | |
| 21 | // Like printf() except output goes to debug log file. Might be defined to do |
| 22 | // nothing (not even evaluate its arguments). |
| 23 | // void dprintf( const char* format, ... ); |
| 24 | #undef dprintf |
| 25 | #define dprintf (1) ? ((void) 0) : (void) |
| 26 | |
| 27 | // If enabled, evaluate expr and if false, make debug log entry with source file |
| 28 | // and line. Meant for finding situations that should be examined further, but that |
| 29 | // don't indicate a problem. In all cases, execution continues normally. |
| 30 | #undef check |
| 31 | #define check( expr ) ((void) 0) |
| 32 | |
| 33 | // If expr returns non-NULL error string, return it from current function, otherwise continue. |
| 34 | #define BLARGG_RETURN_ERR( expr ) do { \ |
| 35 | blargg_err_t blargg_return_err_ = (expr); \ |
| 36 | if ( blargg_return_err_ ) return blargg_return_err_; \ |
| 37 | } while ( 0 ) |
| 38 | |
| 39 | // If ptr is NULL, return out of memory error string. |
| 40 | #define BLARGG_CHECK_ALLOC( ptr ) do { if ( !(ptr) ) return "Out of memory"; } while ( 0 ) |
| 41 | |
| 42 | #endif |
| 43 | |
| 44 | |