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
+10 -23
View File
@@ -36,14 +36,9 @@ int w_CompressedData_getWidth(lua_State *L)
CompressedData *t = luax_checkcompresseddata(L, 1);
int miplevel = luaL_optinteger(L, 2, 1);
int width = 0;
try
{
width = t->getWidth(miplevel >= 1 ? miplevel - 1 : 0);
}
catch (love::Exception &e)
{
return luaL_error(L, "%s", e.what());
}
EXCEPT_GUARD(width = t->getWidth(miplevel >= 1 ? miplevel - 1 : 0);)
lua_pushinteger(L, width);
return 1;
}
@@ -53,14 +48,9 @@ int w_CompressedData_getHeight(lua_State *L)
CompressedData *t = luax_checkcompresseddata(L, 1);
int miplevel = luaL_optinteger(L, 2, 1);
int height = 0;
try
{
height = t->getHeight(miplevel >= 1 ? miplevel - 1 : 0);
}
catch (love::Exception &e)
{
return luaL_error(L, "%s", e.what());
}
EXCEPT_GUARD(height = t->getHeight(miplevel >= 1 ? miplevel - 1 : 0);)
lua_pushinteger(L, height);
return 1;
}
@@ -70,15 +60,12 @@ int w_CompressedData_getDimensions(lua_State *L)
CompressedData *t = luax_checkcompresseddata(L, 1);
int miplevel = luaL_optinteger(L, 2, 1);
int width = 0, height = 0;
try
{
EXCEPT_GUARD(
width = t->getWidth(miplevel >= 1 ? miplevel - 1 : 0);
height = t->getHeight(miplevel >= 1 ? miplevel - 1 : 0);
}
catch (love::Exception &e)
{
return luaL_error(L, "%s", e.what());
}
)
lua_pushinteger(L, width);
lua_pushinteger(L, height);
return 2;
+7 -42
View File
@@ -43,14 +43,8 @@ int w_newImageData(lua_State *L)
return luaL_error(L, "Invalid image size.");
ImageData *t = 0;
try
{
t = instance->newImageData(w, h);
}
catch(love::Exception &e)
{
return luaL_error(L, "%s", e.what());
}
EXCEPT_GUARD(t = instance->newImageData(w, h);)
luax_pushtype(L, "ImageData", IMAGE_IMAGE_DATA_T, t);
return 1;
}
@@ -64,17 +58,9 @@ int w_newImageData(lua_State *L)
love::filesystem::FileData *data = luax_checktype<love::filesystem::FileData>(L, 1, "FileData", FILESYSTEM_FILE_DATA_T);
ImageData *t = 0;
try
{
t = instance->newImageData(data);
}
catch (love::Exception &e)
{
return luaL_error(L, "%s", e.what());
}
EXCEPT_GUARD(t = instance->newImageData(data);)
luax_pushtype(L, "ImageData", IMAGE_IMAGE_DATA_T, t);
return 1;
}
@@ -87,17 +73,9 @@ int w_newCompressedData(lua_State *L)
love::filesystem::FileData *data = luax_checktype<love::filesystem::FileData>(L, 1, "FileData", FILESYSTEM_FILE_DATA_T);
CompressedData *t = 0;
try
{
t = instance->newCompressedData(data);
}
catch(love::Exception &e)
{
return luaL_error(L, "%s", e.what());
}
EXCEPT_GUARD(t = instance->newCompressedData(data);)
luax_pushtype(L, "CompressedData", IMAGE_COMPRESSED_DATA_T, t);
return 1;
}
@@ -110,14 +88,8 @@ int w_isCompressed(lua_State *L)
love::filesystem::FileData *data = luax_checktype<love::filesystem::FileData>(L, 1, "FileData", FILESYSTEM_FILE_DATA_T);
bool compressed = false;
try
{
compressed = instance->isCompressed(data);
}
catch (love::Exception &e)
{
return luaL_error(L, "%s", e.what());
}
EXCEPT_GUARD(compressed = instance->isCompressed(data);)
luax_pushboolean(L, compressed);
return 1;
}
@@ -142,14 +114,7 @@ extern "C" int luaopen_love_image(lua_State *L)
{
if (instance == 0)
{
try
{
instance = new love::image::magpie::Image();
}
catch(Exception &e)
{
return luaL_error(L, "%s", e.what());
}
EXCEPT_GUARD(instance = new love::image::magpie::Image();)
}
else
instance->retain();
+5 -24
View File
@@ -61,14 +61,9 @@ int w_ImageData_getPixel(lua_State *L)
int x = luaL_checkint(L, 2);
int y = luaL_checkint(L, 3);
pixel c;
try
{
c = t->getPixel(x, y);
}
catch(love::Exception &e)
{
return luaL_error(L, "%s", e.what());
}
EXCEPT_GUARD(c = t->getPixel(x, y);)
lua_pushnumber(L, c.r);
lua_pushnumber(L, c.g);
lua_pushnumber(L, c.b);
@@ -103,14 +98,7 @@ int w_ImageData_setPixel(lua_State *L)
c.a = (unsigned char)luaL_optinteger(L, 7, 255);
}
try
{
t->setPixel(x, y, c);
}
catch(love::Exception &e)
{
return luaL_error(L, "%s", e.what());
}
EXCEPT_GUARD(t->setPixel(x, y, c);)
return 0;
}
@@ -281,14 +269,7 @@ int w_ImageData_encode(lua_State *L)
return luaL_error(L, "Invalid image format '%s'.", fmt);
}
try
{
t->encode(file, format);
}
catch(love::Exception &e)
{
return luaL_error(L, e.what());
}
EXCEPT_GUARD(t->encode(file, format);)
return 0;
}