From 5ce850570f30c103ef1daa3fe5de0251dd28911d Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Mon, 23 Apr 2012 19:46:05 -0700 Subject: Add try/catch-like macros to handle errors, and convert alSource.c to use them --- OpenAL32/Include/alMain.h | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'OpenAL32/Include') 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 #include #include +#include #ifdef HAVE_FENV_H #include @@ -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 -- cgit v1.2.3