aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2013-03-24 13:55:41 -0700
committerChris Robinson <[email protected]>2013-03-24 13:55:41 -0700
commit43b406ad9bb32ebde78d26255a2a4f4a09a29926 (patch)
tree6df448e540966a83070fd1155b9f64a0a00340f5
parentdd48375bd6569d8695291d68152fe45016bf37b1 (diff)
Simplify al_try code
-rw-r--r--OpenAL32/Include/alMain.h37
-rw-r--r--OpenAL32/alAuxEffectSlot.c10
-rw-r--r--OpenAL32/alBuffer.c9
-rw-r--r--OpenAL32/alEffect.c7
-rw-r--r--OpenAL32/alFilter.c9
-rw-r--r--OpenAL32/alSource.c28
-rw-r--r--OpenAL32/alState.c6
7 files changed, 41 insertions, 65 deletions
diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h
index 198ab436..e6f45acf 100644
--- a/OpenAL32/Include/alMain.h
+++ b/OpenAL32/Include/alMain.h
@@ -838,37 +838,24 @@ void FillCPUCaps(ALuint capfilter);
* 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)
+#define al_try do { \
+ int _al_in_try_block = 1;
+/** Marks the end of the try block. */
+#define al_endtry _al_endtry_label: \
+ (void)_al_in_try_block; \
+} 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.
+ * The try block is terminated, and execution jumps to al_endtry.
*/
-#define al_throw(e) do { \
- _al_err = (e); \
- assert(_al_err != 0); \
- goto _al_try_label; \
+#define al_throw do { \
+ _al_in_try_block = 0; \
+ goto _al_endtry_label; \
} while(0)
-/** Sets an AL error on the given context, before throwing the error code. */
+/** Sets an AL error on the given context, before throwing. */
#define al_throwerr(ctx, err) do { \
alSetError((ctx), (err)); \
- al_throw((err)); \
+ al_throw; \
} while(0)
/**
diff --git a/OpenAL32/alAuxEffectSlot.c b/OpenAL32/alAuxEffectSlot.c
index 20a37e95..dbaccaa2 100644
--- a/OpenAL32/alAuxEffectSlot.c
+++ b/OpenAL32/alAuxEffectSlot.c
@@ -58,6 +58,7 @@ AL_API ALvoid AL_APIENTRY alGenAuxiliaryEffectSlots(ALsizei n, ALuint *effectslo
if(!slot || (err=InitEffectSlot(slot)) != AL_NO_ERROR)
{
al_free(slot);
+ alDeleteAuxiliaryEffectSlots(cur, effectslots);
al_throwerr(Context, err);
break;
}
@@ -71,6 +72,7 @@ AL_API ALvoid AL_APIENTRY alGenAuxiliaryEffectSlots(ALsizei n, ALuint *effectslo
ALeffectState_Destroy(slot->EffectState);
al_free(slot);
+ alDeleteAuxiliaryEffectSlots(cur, effectslots);
al_throwerr(Context, err);
}
@@ -78,12 +80,10 @@ AL_API ALvoid AL_APIENTRY alGenAuxiliaryEffectSlots(ALsizei n, ALuint *effectslo
}
err = AddEffectSlotArray(Context, n, effectslots);
if(err != AL_NO_ERROR)
- al_throwerr(Context, err);
- }
- al_catchany()
- {
- if(cur > 0)
+ {
alDeleteAuxiliaryEffectSlots(cur, effectslots);
+ al_throwerr(Context, err);
+ }
}
al_endtry;
diff --git a/OpenAL32/alBuffer.c b/OpenAL32/alBuffer.c
index 29f3e617..41444ac2 100644
--- a/OpenAL32/alBuffer.c
+++ b/OpenAL32/alBuffer.c
@@ -198,7 +198,10 @@ AL_API ALvoid AL_APIENTRY alGenBuffers(ALsizei n, ALuint *buffers)
{
ALbuffer *buffer = calloc(1, sizeof(ALbuffer));
if(!buffer)
+ {
+ alDeleteBuffers(cur, buffers);
al_throwerr(Context, AL_OUT_OF_MEMORY);
+ }
RWLockInit(&buffer->lock);
err = NewThunkEntry(&buffer->id);
@@ -210,17 +213,13 @@ AL_API ALvoid AL_APIENTRY alGenBuffers(ALsizei n, ALuint *buffers)
memset(buffer, 0, sizeof(ALbuffer));
free(buffer);
+ alDeleteBuffers(cur, buffers);
al_throwerr(Context, err);
}
buffers[cur] = buffer->id;
}
}
- al_catchany()
- {
- if(cur > 0)
- alDeleteBuffers(cur, buffers);
- }
al_endtry;
ALCcontext_DecRef(Context);
diff --git a/OpenAL32/alEffect.c b/OpenAL32/alEffect.c
index b4fe8173..26d5398d 100644
--- a/OpenAL32/alEffect.c
+++ b/OpenAL32/alEffect.c
@@ -59,6 +59,7 @@ AL_API ALvoid AL_APIENTRY alGenEffects(ALsizei n, ALuint *effects)
if(!effect || (err=InitEffect(effect)) != AL_NO_ERROR)
{
free(effect);
+ alDeleteEffects(cur, effects);
al_throwerr(Context, err);
}
@@ -71,17 +72,13 @@ AL_API ALvoid AL_APIENTRY alGenEffects(ALsizei n, ALuint *effects)
memset(effect, 0, sizeof(ALeffect));
free(effect);
+ alDeleteEffects(cur, effects);
al_throwerr(Context, err);
}
effects[cur] = effect->id;
}
}
- al_catchany()
- {
- if(cur > 0)
- alDeleteEffects(cur, effects);
- }
al_endtry;
ALCcontext_DecRef(Context);
diff --git a/OpenAL32/alFilter.c b/OpenAL32/alFilter.c
index a03ee2d8..775eabde 100644
--- a/OpenAL32/alFilter.c
+++ b/OpenAL32/alFilter.c
@@ -50,7 +50,10 @@ AL_API ALvoid AL_APIENTRY alGenFilters(ALsizei n, ALuint *filters)
{
ALfilter *filter = calloc(1, sizeof(ALfilter));
if(!filter)
+ {
+ alDeleteFilters(cur, filters);
al_throwerr(Context, AL_OUT_OF_MEMORY);
+ }
InitFilterParams(filter, AL_FILTER_NULL);
err = NewThunkEntry(&filter->id);
@@ -62,17 +65,13 @@ AL_API ALvoid AL_APIENTRY alGenFilters(ALsizei n, ALuint *filters)
memset(filter, 0, sizeof(ALfilter));
free(filter);
+ alDeleteFilters(cur, filters);
al_throwerr(Context, err);
}
filters[cur] = filter->id;
}
}
- al_catchany()
- {
- if(cur > 0)
- alDeleteFilters(cur, filters);
- }
al_endtry;
ALCcontext_DecRef(Context);
diff --git a/OpenAL32/alSource.c b/OpenAL32/alSource.c
index 5dbea314..f98b31ea 100644
--- a/OpenAL32/alSource.c
+++ b/OpenAL32/alSource.c
@@ -1230,7 +1230,10 @@ AL_API ALvoid AL_APIENTRY alGenSources(ALsizei n, ALuint *sources)
{
ALsource *source = al_calloc(16, sizeof(ALsource));
if(!source)
+ {
+ alDeleteSources(cur, sources);
al_throwerr(Context, AL_OUT_OF_MEMORY);
+ }
InitSourceParams(source);
err = NewThunkEntry(&source->id);
@@ -1242,17 +1245,13 @@ AL_API ALvoid AL_APIENTRY alGenSources(ALsizei n, ALuint *sources)
memset(source, 0, sizeof(ALsource));
al_free(source);
+ alDeleteSources(cur, sources);
al_throwerr(Context, err);
}
sources[cur] = source->id;
}
}
- al_catchany()
- {
- if(cur > 0)
- alDeleteSources(cur, sources);
- }
al_endtry;
ALCcontext_DecRef(Context);
@@ -2169,24 +2168,23 @@ AL_API ALvoid AL_APIENTRY alSourceQueueBuffers(ALuint source, ALsizei nb, const
BufferListStart->prev = BufferList;
BufferList->next = BufferListStart;
}
+ BufferListStart = NULL;
Source->BuffersInQueue += nb;
UnlockContext(Context);
}
- al_catchany()
+ al_endtry;
+
+ while(BufferListStart)
{
- while(BufferListStart)
- {
- BufferList = BufferListStart;
- BufferListStart = BufferList->next;
+ BufferList = BufferListStart;
+ BufferListStart = BufferList->next;
- if(BufferList->buffer)
- DecrementRef(&BufferList->buffer->ref);
- free(BufferList);
- }
+ if(BufferList->buffer)
+ DecrementRef(&BufferList->buffer->ref);
+ free(BufferList);
}
- al_endtry;
ALCcontext_DecRef(Context);
}
diff --git a/OpenAL32/alState.c b/OpenAL32/alState.c
index 678e9e94..9341050f 100644
--- a/OpenAL32/alState.c
+++ b/OpenAL32/alState.c
@@ -436,7 +436,7 @@ AL_API ALvoid AL_APIENTRY alGetIntegerv(ALenum pname, ALint *values)
AL_API const ALchar* AL_APIENTRY alGetString(ALenum pname)
{
- const ALchar *value;
+ const ALchar *value = NULL;
ALCcontext *Context;
Context = GetContextRef();
@@ -490,10 +490,6 @@ AL_API const ALchar* AL_APIENTRY alGetString(ALenum pname)
al_throwerr(Context, AL_INVALID_ENUM);
}
}
- al_catchany()
- {
- value = NULL;
- }
al_endtry;
ALCcontext_DecRef(Context);