diff options
author | Chris Robinson <[email protected]> | 2012-04-23 19:46:05 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2012-04-23 19:46:05 -0700 |
commit | 5ce850570f30c103ef1daa3fe5de0251dd28911d (patch) | |
tree | 507e6a99972857811b2b77f8138ab828a122767c /OpenAL32/Include | |
parent | 648464a2da25277c4b90dac8484053ce98581a9b (diff) |
Add try/catch-like macros to handle errors, and convert alSource.c to use them
Diffstat (limited to 'OpenAL32/Include')
-rw-r--r-- | OpenAL32/Include/alMain.h | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h index ca8d6340..0802fc32 100644 --- a/OpenAL32/Include/alMain.h +++ b/OpenAL32/Include/alMain.h @@ -4,6 +4,7 @@ #include <string.h> #include <stdio.h> #include <stdarg.h> +#include <assert.h> #ifdef HAVE_FENV_H #include <fenv.h> @@ -760,6 +761,52 @@ extern enum LogLevel LogLevel; extern ALint RTPrioLevel; +/** + * Starts a try block. Must not be nested within another try block within the + * same function. + */ +#define al_try do { \ + int _al_err=0; \ +_al_try_label: \ + if(_al_err == 0) +/** + * After a try or another catch block, runs the next block if the given value + * was thrown. + */ +#define al_catch(val) else if(_al_err == (val)) +/** + * After a try or catch block, runs the next block for any value thrown and not + * caught. + */ +#define al_catchany() else +/** Marks the end of the final catch (or the try) block. */ +#define al_endtry } while(0) + +/** + * The given integer value is "thrown" so as to be caught by a catch block. + * Must be called in a try block within the same function. The value must not + * be 0. + */ +#define al_throw(e) do { \ + _al_err = (e); \ + assert(_al_err != 0); \ + goto _al_try_label; \ +} while(0) +/** Sets an AL error on the given context, before throwing the error code. */ +#define al_throwerr(ctx, err) do { \ + alSetError((ctx), (err)); \ + al_throw((err)); \ +} while(0) + +/** + * Throws an AL_INVALID_VALUE error with the given ctx if the given condition + * is false. + */ +#define CHECK_VALUE(ctx, cond) do { \ + if(!(cond)) \ + al_throwerr((ctx), AL_INVALID_VALUE); \ +} while(0) + #ifdef __cplusplus } #endif |