Simplify al_try code
This commit is contained in:
parent
dd48375bd6
commit
43b406ad9b
@ -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)
|
||||
|
||||
/**
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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,25 +2168,24 @@ 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()
|
||||
{
|
||||
while(BufferListStart)
|
||||
{
|
||||
BufferList = BufferListStart;
|
||||
BufferListStart = BufferList->next;
|
||||
|
||||
if(BufferList->buffer)
|
||||
DecrementRef(&BufferList->buffer->ref);
|
||||
free(BufferList);
|
||||
}
|
||||
}
|
||||
al_endtry;
|
||||
|
||||
while(BufferListStart)
|
||||
{
|
||||
BufferList = BufferListStart;
|
||||
BufferListStart = BufferList->next;
|
||||
|
||||
if(BufferList->buffer)
|
||||
DecrementRef(&BufferList->buffer->ref);
|
||||
free(BufferList);
|
||||
}
|
||||
|
||||
ALCcontext_DecRef(Context);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user