aboutsummaryrefslogtreecommitdiffstats
path: root/OpenAL32
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2012-04-25 00:24:02 -0700
committerChris Robinson <[email protected]>2012-04-25 00:24:02 -0700
commitfdc4133ac903083af3055f60e2a89be0082e2338 (patch)
tree247288836cccdea5cfa3e8d0edccdc6129935f0b /OpenAL32
parent3833c021c0b10a59fc3ec263d1f6ea8a9f3c9769 (diff)
Partially convert alEffect.c and alFilter.c to the new error handling
Diffstat (limited to 'OpenAL32')
-rw-r--r--OpenAL32/alEffect.c60
-rw-r--r--OpenAL32/alFilter.c59
2 files changed, 50 insertions, 69 deletions
diff --git a/OpenAL32/alEffect.c b/OpenAL32/alEffect.c
index a2fbbc5f..e9093f5f 100644
--- a/OpenAL32/alEffect.c
+++ b/OpenAL32/alEffect.c
@@ -40,27 +40,25 @@ static void InitEffectParams(ALeffect *effect, ALenum type);
AL_API ALvoid AL_APIENTRY alGenEffects(ALsizei n, ALuint *effects)
{
ALCcontext *Context;
- ALsizei i;
+ ALsizei cur = 0;
Context = GetContextRef();
if(!Context) return;
- if(n < 0 || IsBadWritePtr((void*)effects, n * sizeof(ALuint)))
- alSetError(Context, AL_INVALID_VALUE);
- else
+ al_try
{
ALCdevice *device = Context->Device;
ALenum err;
- for(i = 0;i < n;i++)
+ CHECK_VALUE(Context, n >= 0);
+ for(cur = 0;cur < n;cur++)
{
ALeffect *effect = calloc(1, sizeof(ALeffect));
- if(!effect || InitEffect(effect) != AL_NO_ERROR)
+ err = AL_OUT_OF_MEMORY;
+ if(!effect || (err=InitEffect(effect)) != AL_NO_ERROR)
{
free(effect);
- alSetError(Context, AL_OUT_OF_MEMORY);
- alDeleteEffects(i, effects);
- break;
+ al_throwerr(Context, err);
}
err = NewThunkEntry(&effect->id);
@@ -72,14 +70,18 @@ AL_API ALvoid AL_APIENTRY alGenEffects(ALsizei n, ALuint *effects)
memset(effect, 0, sizeof(ALeffect));
free(effect);
- alSetError(Context, err);
- alDeleteEffects(i, effects);
- break;
+ al_throwerr(Context, err);
}
- effects[i] = effect->id;
+ effects[cur] = effect->id;
}
}
+ al_catchany()
+ {
+ if(cur > 0)
+ alDeleteEffects(cur, effects);
+ }
+ al_endtry;
ALCcontext_DecRef(Context);
}
@@ -87,43 +89,33 @@ AL_API ALvoid AL_APIENTRY alGenEffects(ALsizei n, ALuint *effects)
AL_API ALvoid AL_APIENTRY alDeleteEffects(ALsizei n, const ALuint *effects)
{
ALCcontext *Context;
- ALCdevice *device;
- ALeffect *ALEffect;
+ ALeffect *Effect;
ALsizei i;
Context = GetContextRef();
if(!Context) return;
- device = Context->Device;
- if(n < 0)
- alSetError(Context, AL_INVALID_VALUE);
- else
+ al_try
{
- // Check that all effects are valid
+ ALCdevice *device = Context->Device;
+ CHECK_VALUE(Context, n >= 0);
for(i = 0;i < n;i++)
{
- if(!effects[i])
- continue;
-
- if(LookupEffect(device, effects[i]) == NULL)
- {
- alSetError(Context, AL_INVALID_NAME);
- n = 0;
- break;
- }
+ if(effects[i] && LookupEffect(device, effects[i]) == NULL)
+ al_throwerr(Context, AL_INVALID_NAME);
}
for(i = 0;i < n;i++)
{
- // Recheck that the effect is valid, because there could be duplicated names
- if((ALEffect=RemoveEffect(device, effects[i])) == NULL)
+ if((Effect=RemoveEffect(device, effects[i])) == NULL)
continue;
- FreeThunkEntry(ALEffect->id);
+ FreeThunkEntry(Effect->id);
- memset(ALEffect, 0, sizeof(ALeffect));
- free(ALEffect);
+ memset(Effect, 0, sizeof(*Effect));
+ free(Effect);
}
}
+ al_endtry;
ALCcontext_DecRef(Context);
}
diff --git a/OpenAL32/alFilter.c b/OpenAL32/alFilter.c
index b5186470..d943d9f1 100644
--- a/OpenAL32/alFilter.c
+++ b/OpenAL32/alFilter.c
@@ -36,27 +36,22 @@ static void InitFilterParams(ALfilter *filter, ALenum type);
AL_API ALvoid AL_APIENTRY alGenFilters(ALsizei n, ALuint *filters)
{
ALCcontext *Context;
- ALsizei i;
+ ALsizei cur = 0;
Context = GetContextRef();
if(!Context) return;
- if(n < 0 || IsBadWritePtr((void*)filters, n * sizeof(ALuint)))
- alSetError(Context, AL_INVALID_VALUE);
- else
+ al_try
{
ALCdevice *device = Context->Device;
ALenum err;
- for(i = 0;i < n;i++)
+ CHECK_VALUE(Context, n >= 0);
+ for(cur = 0;cur < n;cur++)
{
ALfilter *filter = calloc(1, sizeof(ALfilter));
if(!filter)
- {
- alSetError(Context, AL_OUT_OF_MEMORY);
- alDeleteFilters(i, filters);
- break;
- }
+ al_throwerr(Context, AL_OUT_OF_MEMORY);
InitFilterParams(filter, AL_FILTER_NULL);
err = NewThunkEntry(&filter->id);
@@ -68,14 +63,18 @@ AL_API ALvoid AL_APIENTRY alGenFilters(ALsizei n, ALuint *filters)
memset(filter, 0, sizeof(ALfilter));
free(filter);
- alSetError(Context, err);
- alDeleteFilters(i, filters);
- break;
+ al_throwerr(Context, err);
}
- filters[i] = filter->id;
+ filters[cur] = filter->id;
}
}
+ al_catchany()
+ {
+ if(cur > 0)
+ alDeleteFilters(cur, filters);
+ }
+ al_endtry;
ALCcontext_DecRef(Context);
}
@@ -83,43 +82,33 @@ AL_API ALvoid AL_APIENTRY alGenFilters(ALsizei n, ALuint *filters)
AL_API ALvoid AL_APIENTRY alDeleteFilters(ALsizei n, const ALuint *filters)
{
ALCcontext *Context;
- ALCdevice *device;
- ALfilter *ALFilter;
+ ALfilter *Filter;
ALsizei i;
Context = GetContextRef();
if(!Context) return;
- device = Context->Device;
- if(n < 0)
- alSetError(Context, AL_INVALID_VALUE);
- else
+ al_try
{
- // Check that all filters are valid
+ ALCdevice *device = Context->Device;
+ CHECK_VALUE(Context, n >= 0);
for(i = 0;i < n;i++)
{
- if(!filters[i])
- continue;
-
- if(LookupFilter(device, filters[i]) == NULL)
- {
- alSetError(Context, AL_INVALID_NAME);
- n = 0;
- break;
- }
+ if(filters[i] && LookupFilter(device, filters[i]) == NULL)
+ al_throwerr(Context, AL_INVALID_NAME);
}
for(i = 0;i < n;i++)
{
- // Recheck that the filter is valid, because there could be duplicated names
- if((ALFilter=RemoveFilter(device, filters[i])) == NULL)
+ if((Filter=RemoveFilter(device, filters[i])) == NULL)
continue;
- FreeThunkEntry(ALFilter->id);
+ FreeThunkEntry(Filter->id);
- memset(ALFilter, 0, sizeof(ALfilter));
- free(ALFilter);
+ memset(Filter, 0, sizeof(*Filter));
+ free(Filter);
}
}
+ al_endtry;
ALCcontext_DecRef(Context);
}