Fixed undefined behaviour when love exceptions are converted into Lua errors (resolves issue #729)

This commit is contained in:
Alex Szpakowski
2013-09-05 23:17:29 -03:00
parent 389e99bf2c
commit 06f80d5c08
45 changed files with 349 additions and 873 deletions
+9 -37
View File
@@ -41,20 +41,11 @@ int w_newSoundData(lua_State *L)
int bitDepth = luaL_optint(L, 3, Decoder::DEFAULT_BIT_DEPTH);
int channels = luaL_optint(L, 4, Decoder::DEFAULT_CHANNELS);
try
{
t = instance->newSoundData(samples, sampleRate, bitDepth, channels);
}
catch(love::Exception &e)
{
return luaL_error(L, e.what());
}
EXCEPT_GUARD(t = instance->newSoundData(samples, sampleRate, bitDepth, channels);)
}
// Must be string or decoder.
else
{
// Convert to Decoder, if necessary.
if (!luax_istype(L, 1, SOUND_DECODER_T))
{
@@ -62,14 +53,7 @@ int w_newSoundData(lua_State *L)
lua_replace(L, 1);
}
try
{
t = instance->newSoundData(luax_checkdecoder(L, 1));
}
catch(love::Exception &e)
{
return luaL_error(L, e.what());
}
EXCEPT_GUARD(t = instance->newSoundData(luax_checkdecoder(L, 1));)
}
luax_pushtype(L, "SoundData", SOUND_SOUND_DATA_T, t);
@@ -86,18 +70,13 @@ int w_newDecoder(lua_State *L)
int bufferSize = luaL_optint(L, 2, Decoder::DEFAULT_BUFFER_SIZE);
try
{
Decoder *t = instance->newDecoder(data, bufferSize);
if (t == 0)
return luaL_error(L, "Extension \"%s\" not supported.", data->getExtension().c_str());
luax_pushtype(L, "Decoder", SOUND_DECODER_T, t);
}
catch(love::Exception &e)
{
return luaL_error(L, e.what());
}
Decoder *t = 0;
EXCEPT_GUARD(t = instance->newDecoder(data, bufferSize);)
if (t == 0)
return luaL_error(L, "Extension \"%s\" not supported.", data->getExtension().c_str());
luax_pushtype(L, "Decoder", SOUND_DECODER_T, t);
return 1;
}
@@ -120,14 +99,7 @@ extern "C" int luaopen_love_sound(lua_State *L)
{
if (instance == 0)
{
try
{
instance = new lullaby::Sound();
}
catch(Exception &e)
{
return luaL_error(L, e.what());
}
EXCEPT_GUARD(instance = new lullaby::Sound();)
}
else
instance->retain();
+4 -16
View File
@@ -72,14 +72,8 @@ int w_SoundData_setSample(lua_State *L)
SoundData *sd = luax_checksounddata(L, 1);
int i = (int)lua_tointeger(L, 2);
float sample = (float)lua_tonumber(L, 3);
try
{
sd->setSample(i, sample);
}
catch (love::Exception &e)
{
return luaL_error(L, "%s", e.what());
}
EXCEPT_GUARD(sd->setSample(i, sample);)
return 0;
}
@@ -87,14 +81,8 @@ int w_SoundData_getSample(lua_State *L)
{
SoundData *sd = luax_checksounddata(L, 1);
int i = (int)lua_tointeger(L, 2);
try
{
lua_pushnumber(L, sd->getSample(i));
}
catch (love::Exception &e)
{
return luaL_error(L, "%s", e.what());
}
EXCEPT_GUARD(lua_pushnumber(L, sd->getSample(i));)
return 1;
}