Pass Type to luax_register_type by pointer instead of reference

Since the type is passed to va_start, and apparently that's undefined behaviour if it's a reference.

<Textmode> the best kind of behavior

--HG--
branch : dynamiccore2
This commit is contained in:
Bart van Strien
2016-11-14 21:51:47 +01:00
parent d967a755e5
commit 9f6aa716fa
54 changed files with 60 additions and 59 deletions
+5 -5
View File
@@ -307,9 +307,9 @@ int luax_preload(lua_State *L, lua_CFunction f, const char *name)
return 0;
}
int luax_register_type(lua_State *L, love::Type &type, ...)
int luax_register_type(lua_State *L, love::Type *type, ...)
{
type.init();
type->init();
// Get the place for storing and re-using instantiated love types.
luax_getregistry(L, REGISTRY_OBJECTS);
@@ -336,7 +336,7 @@ int luax_register_type(lua_State *L, love::Type &type, ...)
else
lua_pop(L, 1);
luaL_newmetatable(L, type.getName());
luaL_newmetatable(L, type->getName());
// m.__index = m
lua_pushvalue(L, -1);
@@ -351,12 +351,12 @@ int luax_register_type(lua_State *L, love::Type &type, ...)
lua_setfield(L, -2, "__eq");
// Add tostring function.
lua_pushstring(L, type.getName());
lua_pushstring(L, type->getName());
lua_pushcclosure(L, w__tostring, 1);
lua_setfield(L, -2, "__tostring");
// Add type
lua_pushstring(L, type.getName());
lua_pushstring(L, type->getName());
lua_pushcclosure(L, w__type, 1);
lua_setfield(L, -2, "type");
+3 -2
View File
@@ -249,11 +249,12 @@ int luax_preload(lua_State *L, lua_CFunction f, const char *name);
/**
* Register a new type.
* NOTE: The type is passed by pointer instead of reference because calling va_start
* on a reference is undefined behaviour.
* @param type The type.
* @param name The type's human-readable name
* @param ... The list of lists of member functions for the type. (of type luaL_Reg*)
**/
int luax_register_type(lua_State *L, love::Type &type, ...);
int luax_register_type(lua_State *L, love::Type *type, ...);
/**
* Pushes the metatable of the specified type onto the stack.
+1 -1
View File
@@ -59,7 +59,7 @@ const luaL_Reg w_Data_functions[] =
int w_Data_open(lua_State *L)
{
luax_register_type(L, Data::type, w_Data_functions, nullptr);
luax_register_type(L, &Data::type, w_Data_functions, nullptr);
return 0;
}
+1 -1
View File
@@ -450,7 +450,7 @@ static const luaL_Reg w_Source_functions[] =
extern "C" int luaopen_source(lua_State *L)
{
return luax_register_type(L, love::audio::Source::type, w_Source_functions, nullptr);
return luax_register_type(L, &love::audio::Source::type, w_Source_functions, nullptr);
}
} // audio
+1 -1
View File
@@ -33,7 +33,7 @@ DroppedFile *luax_checkdroppedfile(lua_State *L, int idx)
extern "C" int luaopen_droppedfile(lua_State *L)
{
return luax_register_type(L, DroppedFile::type, w_File_functions, nullptr);
return luax_register_type(L, &DroppedFile::type, w_File_functions, nullptr);
}
} // filesystem
+1 -1
View File
@@ -435,7 +435,7 @@ const luaL_Reg w_File_functions[] =
extern "C" int luaopen_file(lua_State *L)
{
return luax_register_type(L, File::type, w_File_functions, nullptr);
return luax_register_type(L, &File::type, w_File_functions, nullptr);
}
} // filesystem
+1 -1
View File
@@ -56,7 +56,7 @@ static const luaL_Reg w_FileData_functions[] =
extern "C" int luaopen_filedata(lua_State *L)
{
return luax_register_type(L, FileData::type, w_Data_functions, w_FileData_functions, nullptr);
return luax_register_type(L, &FileData::type, w_Data_functions, w_FileData_functions, nullptr);
}
} // filesystem
+1 -1
View File
@@ -131,7 +131,7 @@ const luaL_Reg w_GlyphData_functions[] =
extern "C" int luaopen_glyphdata(lua_State *L)
{
return luax_register_type(L, GlyphData::type, w_Data_functions, w_GlyphData_functions, nullptr);
return luax_register_type(L, &GlyphData::type, w_Data_functions, w_GlyphData_functions, nullptr);
}
} // font
+1 -1
View File
@@ -139,7 +139,7 @@ const luaL_Reg w_Rasterizer_functions[] =
extern "C" int luaopen_rasterizer(lua_State *L)
{
return luax_register_type(L, Rasterizer::type, w_Rasterizer_functions, nullptr);
return luax_register_type(L, &Rasterizer::type, w_Rasterizer_functions, nullptr);
}
} // font
+1 -1
View File
@@ -112,7 +112,7 @@ static const luaL_Reg w_Canvas_functions[] =
extern "C" int luaopen_canvas(lua_State *L)
{
return luax_register_type(L, Canvas::type, w_Texture_functions, w_Canvas_functions, nullptr);
return luax_register_type(L, &Canvas::type, w_Texture_functions, w_Canvas_functions, nullptr);
}
} // opengl
+1 -1
View File
@@ -207,7 +207,7 @@ static const luaL_Reg w_Font_functions[] =
extern "C" int luaopen_font(lua_State *L)
{
return luax_register_type(L, Font::type, w_Font_functions, nullptr);
return luax_register_type(L, &Font::type, w_Font_functions, nullptr);
}
} // opengl
@@ -2090,7 +2090,7 @@ static const luaL_Reg functions[] =
static int luaopen_drawable(lua_State *L)
{
return luax_register_type(L, Drawable::type, nullptr);
return luax_register_type(L, &Drawable::type, nullptr);
}
// Types for this module.
+1 -1
View File
@@ -150,7 +150,7 @@ static const luaL_Reg w_Image_functions[] =
extern "C" int luaopen_image(lua_State *L)
{
return luax_register_type(L, Image::type, w_Texture_functions, w_Image_functions, nullptr);
return luax_register_type(L, &Image::type, w_Texture_functions, w_Image_functions, nullptr);
}
} // opengl
+1 -1
View File
@@ -528,7 +528,7 @@ static const luaL_Reg w_Mesh_functions[] =
extern "C" int luaopen_mesh(lua_State *L)
{
return luax_register_type(L, Mesh::type, w_Mesh_functions, nullptr);
return luax_register_type(L, &Mesh::type, w_Mesh_functions, nullptr);
}
} // opengl
@@ -772,7 +772,7 @@ static const luaL_Reg w_ParticleSystem_functions[] =
extern "C" int luaopen_particlesystem(lua_State *L)
{
return luax_register_type(L, ParticleSystem::type, w_ParticleSystem_functions, nullptr);
return luax_register_type(L, &ParticleSystem::type, w_ParticleSystem_functions, nullptr);
}
} // opengl
+1 -1
View File
@@ -317,7 +317,7 @@ static const luaL_Reg w_Shader_functions[] =
extern "C" int luaopen_shader(lua_State *L)
{
return luax_register_type(L, Shader::type, w_Shader_functions, nullptr);
return luax_register_type(L, &Shader::type, w_Shader_functions, nullptr);
}
} // opengl
@@ -257,7 +257,7 @@ static const luaL_Reg w_SpriteBatch_functions[] =
extern "C" int luaopen_spritebatch(lua_State *L)
{
return luax_register_type(L, SpriteBatch::type, w_SpriteBatch_functions, nullptr);
return luax_register_type(L, &SpriteBatch::type, w_SpriteBatch_functions, nullptr);
}
} // opengl
+1 -1
View File
@@ -245,7 +245,7 @@ static const luaL_Reg w_Text_functions[] =
extern "C" int luaopen_text(lua_State *L)
{
return luax_register_type(L, Text::type, w_Text_functions, nullptr);
return luax_register_type(L, &Text::type, w_Text_functions, nullptr);
}
} // opengl
+1 -1
View File
@@ -143,7 +143,7 @@ static const luaL_Reg functions[] =
int luaopen_video(lua_State *L)
{
int ret = luax_register_type(L, Video::type, functions, nullptr);
int ret = luax_register_type(L, &Video::type, functions, nullptr);
luaL_loadbuffer(L, video_lua, sizeof(video_lua), "Video.lua");
luax_gettypemetatable(L, Video::type);
+1 -1
View File
@@ -84,7 +84,7 @@ static const luaL_Reg w_Quad_functions[] =
extern "C" int luaopen_quad(lua_State *L)
{
return luax_register_type(L, Quad::type, w_Quad_functions, nullptr);
return luax_register_type(L, &Quad::type, w_Quad_functions, nullptr);
}
} // graphics
+1 -1
View File
@@ -139,7 +139,7 @@ const luaL_Reg w_Texture_functions[] =
extern "C" int luaopen_texture(lua_State *L)
{
return luax_register_type(L, Texture::type, w_Texture_functions, nullptr);
return luax_register_type(L, &Texture::type, w_Texture_functions, nullptr);
}
} // graphics
@@ -106,7 +106,7 @@ static const luaL_Reg w_CompressedImageData_functions[] =
extern "C" int luaopen_compressedimagedata(lua_State *L)
{
return luax_register_type(L, CompressedImageData::type, w_Data_functions, w_CompressedImageData_functions, nullptr);
return luax_register_type(L, &CompressedImageData::type, w_Data_functions, w_CompressedImageData_functions, nullptr);
}
} // image
+1 -1
View File
@@ -366,7 +366,7 @@ static const luaL_Reg w_ImageData_functions[] =
extern "C" int luaopen_imagedata(lua_State *L)
{
int ret = luax_register_type(L, ImageData::type, w_Data_functions, w_ImageData_functions, nullptr);
int ret = luax_register_type(L, &ImageData::type, w_Data_functions, w_ImageData_functions, nullptr);
luax_gettypemetatable(L, ImageData::type);
+1 -1
View File
@@ -296,7 +296,7 @@ static const luaL_Reg w_Joystick_functions[] =
extern "C" int luaopen_joystick(lua_State *L)
{
return luax_register_type(L, Joystick::type, w_Joystick_functions, nullptr);
return luax_register_type(L, &Joystick::type, w_Joystick_functions, nullptr);
}
} // joystick
+1 -1
View File
@@ -234,7 +234,7 @@ static const luaL_Reg w_BezierCurve_functions[] =
extern "C" int luaopen_beziercurve(lua_State *L)
{
return luax_register_type(L, BezierCurve::type, w_BezierCurve_functions, nullptr);
return luax_register_type(L, &BezierCurve::type, w_BezierCurve_functions, nullptr);
}
} // math
+1 -1
View File
@@ -53,7 +53,7 @@ static const luaL_Reg w_CompressedData_functions[] =
extern "C" int luaopen_compresseddata(lua_State *L)
{
return luax_register_type(L, CompressedData::type, w_Data_functions, w_CompressedData_functions, nullptr);
return luax_register_type(L, &CompressedData::type, w_Data_functions, w_CompressedData_functions, nullptr);
}
} // math
+1 -1
View File
@@ -147,7 +147,7 @@ static const luaL_Reg w_RandomGenerator_functions[] =
extern "C" int luaopen_randomgenerator(lua_State *L)
{
int n = luax_register_type(L, RandomGenerator::type, w_RandomGenerator_functions, nullptr);
int n = luax_register_type(L, &RandomGenerator::type, w_RandomGenerator_functions, nullptr);
luax_gettypemetatable(L, RandomGenerator::type);
+1 -1
View File
@@ -61,7 +61,7 @@ static const luaL_Reg w_Cursor_functions[] =
extern "C" int luaopen_cursor(lua_State *L)
{
return luax_register_type(L, Cursor::type, w_Cursor_functions, nullptr);
return luax_register_type(L, &Cursor::type, w_Cursor_functions, nullptr);
}
} // mouse
+1 -1
View File
@@ -650,7 +650,7 @@ static const luaL_Reg w_Body_functions[] =
extern "C" int luaopen_body(lua_State *L)
{
return luax_register_type(L, Body::type, w_Body_functions, nullptr);
return luax_register_type(L, &Body::type, w_Body_functions, nullptr);
}
} // box2d
@@ -149,7 +149,7 @@ static const luaL_Reg w_ChainShape_functions[] =
extern "C" int luaopen_chainshape(lua_State *L)
{
return luax_register_type(L, ChainShape::type, w_Shape_functions, w_ChainShape_functions, nullptr);
return luax_register_type(L, &ChainShape::type, w_Shape_functions, w_ChainShape_functions, nullptr);
}
} // box2d
@@ -75,7 +75,7 @@ static const luaL_Reg w_CircleShape_functions[] =
extern "C" int luaopen_circleshape(lua_State *L)
{
return luax_register_type(L, CircleShape::type, w_Shape_functions, w_CircleShape_functions, nullptr);
return luax_register_type(L, &CircleShape::type, w_Shape_functions, w_CircleShape_functions, nullptr);
}
} // box2d
+1 -1
View File
@@ -181,7 +181,7 @@ static const luaL_Reg w_Contact_functions[] =
extern "C" int luaopen_contact(lua_State *L)
{
return luax_register_type(L, Contact::type, w_Contact_functions, nullptr);
return luax_register_type(L, &Contact::type, w_Contact_functions, nullptr);
}
} // box2d
@@ -93,7 +93,7 @@ static const luaL_Reg w_DistanceJoint_functions[] =
extern "C" int luaopen_distancejoint(lua_State *L)
{
return luax_register_type(L, DistanceJoint::type, w_Joint_functions, w_DistanceJoint_functions, nullptr);
return luax_register_type(L, &DistanceJoint::type, w_Joint_functions, w_DistanceJoint_functions, nullptr);
}
} // box2d
+1 -1
View File
@@ -105,7 +105,7 @@ static const luaL_Reg w_EdgeShape_functions[] =
extern "C" int luaopen_edgeshape(lua_State *L)
{
return luax_register_type(L, EdgeShape::type, w_Shape_functions, w_EdgeShape_functions, nullptr);
return luax_register_type(L, &EdgeShape::type, w_Shape_functions, w_EdgeShape_functions, nullptr);
}
} // box2d
+1 -1
View File
@@ -302,7 +302,7 @@ static const luaL_Reg w_Fixture_functions[] =
extern "C" int luaopen_fixture(lua_State *L)
{
return luax_register_type(L, Fixture::type, w_Fixture_functions, nullptr);
return luax_register_type(L, &Fixture::type, w_Fixture_functions, nullptr);
}
} // box2d
@@ -77,7 +77,7 @@ static const luaL_Reg w_FrictionJoint_functions[] =
extern "C" int luaopen_frictionjoint(lua_State *L)
{
return luax_register_type(L, FrictionJoint::type, w_Joint_functions, w_FrictionJoint_functions, nullptr);
return luax_register_type(L, &FrictionJoint::type, w_Joint_functions, w_FrictionJoint_functions, nullptr);
}
} // box2d
+1 -1
View File
@@ -77,7 +77,7 @@ static const luaL_Reg w_GearJoint_functions[] =
extern "C" int luaopen_gearjoint(lua_State *L)
{
return luax_register_type(L, GearJoint::type, w_Joint_functions, w_GearJoint_functions, nullptr);
return luax_register_type(L, &GearJoint::type, w_Joint_functions, w_GearJoint_functions, nullptr);
}
} // box2d
+1 -1
View File
@@ -182,7 +182,7 @@ const luaL_Reg w_Joint_functions[] =
extern "C" int luaopen_joint(lua_State *L)
{
return luax_register_type(L, Joint::type, w_Joint_functions, nullptr);
return luax_register_type(L, &Joint::type, w_Joint_functions, nullptr);
}
} // box2d
@@ -127,7 +127,7 @@ static const luaL_Reg w_MotorJoint_functions[] =
extern "C" int luaopen_motorjoint(lua_State *L)
{
return luax_register_type(L, MotorJoint::type, w_Joint_functions, w_MotorJoint_functions, nullptr);
return luax_register_type(L, &MotorJoint::type, w_Joint_functions, w_MotorJoint_functions, nullptr);
}
@@ -111,7 +111,7 @@ static const luaL_Reg w_MouseJoint_functions[] =
extern "C" int luaopen_mousejoint(lua_State *L)
{
return luax_register_type(L, MouseJoint::type, w_Joint_functions, w_MouseJoint_functions, nullptr);
return luax_register_type(L, &MouseJoint::type, w_Joint_functions, w_MouseJoint_functions, nullptr);
}
} // box2d
@@ -55,7 +55,7 @@ static const luaL_Reg w_PolygonShape_functions[] =
extern "C" int luaopen_polygonshape(lua_State *L)
{
return luax_register_type(L, PolygonShape::type, w_Shape_functions, w_PolygonShape_functions, nullptr);
return luax_register_type(L, &PolygonShape::type, w_Shape_functions, w_PolygonShape_functions, nullptr);
}
} // box2d
@@ -204,7 +204,7 @@ static const luaL_Reg w_PrismaticJoint_functions[] =
extern "C" int luaopen_prismaticjoint(lua_State *L)
{
return luax_register_type(L, PrismaticJoint::type, w_Joint_functions, w_PrismaticJoint_functions, nullptr);
return luax_register_type(L, &PrismaticJoint::type, w_Joint_functions, w_PrismaticJoint_functions, nullptr);
}
} // box2d
@@ -74,7 +74,7 @@ static const luaL_Reg w_PulleyJoint_functions[] =
extern "C" int luaopen_pulleyjoint(lua_State *L)
{
return luax_register_type(L, PulleyJoint::type, w_Joint_functions, w_PulleyJoint_functions, nullptr);
return luax_register_type(L, &PulleyJoint::type, w_Joint_functions, w_PulleyJoint_functions, nullptr);
}
} // box2d
@@ -196,7 +196,7 @@ static const luaL_Reg w_RevoluteJoint_functions[] =
extern "C" int luaopen_revolutejoint(lua_State *L)
{
return luax_register_type(L, RevoluteJoint::type, w_Joint_functions, w_RevoluteJoint_functions, nullptr);
return luax_register_type(L, &RevoluteJoint::type, w_Joint_functions, w_RevoluteJoint_functions, nullptr);
}
} // box2d
+1 -1
View File
@@ -50,7 +50,7 @@ static const luaL_Reg w_RopeJoint_functions[] =
extern "C" int luaopen_ropejoint(lua_State *L)
{
return luax_register_type(L, RopeJoint::type, w_Joint_functions, w_RopeJoint_functions, nullptr);
return luax_register_type(L, &RopeJoint::type, w_Joint_functions, w_RopeJoint_functions, nullptr);
}
} // box2d
+1 -1
View File
@@ -108,7 +108,7 @@ const luaL_Reg w_Shape_functions[] =
extern "C" int luaopen_shape(lua_State *L)
{
return luax_register_type(L, Shape::type, w_Shape_functions, nullptr);
return luax_register_type(L, &Shape::type, w_Shape_functions, nullptr);
}
} // box2d
+1 -1
View File
@@ -84,7 +84,7 @@ static const luaL_Reg w_WeldJoint_functions[] =
extern "C" int luaopen_weldjoint(lua_State *L)
{
return luax_register_type(L, WeldJoint::type, w_Joint_functions, w_WeldJoint_functions, nullptr);
return luax_register_type(L, &WeldJoint::type, w_Joint_functions, w_WeldJoint_functions, nullptr);
}
} // box2d
@@ -160,7 +160,7 @@ static const luaL_Reg w_WheelJoint_functions[] =
extern "C" int luaopen_wheeljoint(lua_State *L)
{
return luax_register_type(L, WheelJoint::type, w_Joint_functions, w_WheelJoint_functions, nullptr);
return luax_register_type(L, &WheelJoint::type, w_Joint_functions, w_WheelJoint_functions, nullptr);
}
} // box2d
+1 -1
View File
@@ -237,7 +237,7 @@ static const luaL_Reg w_World_functions[] =
extern "C" int luaopen_world(lua_State *L)
{
return luax_register_type(L, World::type, w_World_functions, nullptr);
return luax_register_type(L, &World::type, w_World_functions, nullptr);
}
} // box2d
+1 -1
View File
@@ -109,7 +109,7 @@ static const luaL_Reg w_Decoder_functions[] =
extern "C" int luaopen_decoder(lua_State *L)
{
return luax_register_type(L, Decoder::type, w_Decoder_functions, nullptr);
return luax_register_type(L, &Decoder::type, w_Decoder_functions, nullptr);
}
} // sound
+1 -1
View File
@@ -110,7 +110,7 @@ static const luaL_Reg w_SoundData_functions[] =
extern "C" int luaopen_sounddata(lua_State *L)
{
int ret = luax_register_type(L, SoundData::type, w_Data_functions, w_SoundData_functions, nullptr);
int ret = luax_register_type(L, &SoundData::type, w_Data_functions, w_SoundData_functions, nullptr);
luax_gettypemetatable(L, SoundData::type);
+1 -1
View File
@@ -147,7 +147,7 @@ static const luaL_Reg w_Channel_functions[] =
extern "C" int luaopen_channel(lua_State *L)
{
return luax_register_type(L, Channel::type, w_Channel_functions, nullptr);
return luax_register_type(L, &Channel::type, w_Channel_functions, nullptr);
}
} // thread
+1 -1
View File
@@ -87,7 +87,7 @@ static const luaL_Reg w_Thread_functions[] =
extern "C" int luaopen_thread(lua_State *L)
{
return luax_register_type(L, LuaThread::type, w_Thread_functions, nullptr);
return luax_register_type(L, &LuaThread::type, w_Thread_functions, nullptr);
}
} // thread
+1 -1
View File
@@ -124,7 +124,7 @@ static const luaL_Reg videostream_functions[] =
int luaopen_videostream(lua_State *L)
{
return luax_register_type(L, VideoStream::type, videostream_functions, nullptr);
return luax_register_type(L, &VideoStream::type, videostream_functions, nullptr);
}
} // video