Skip to content

Commit b8f423b

Browse files
authored
Fix multiple issues. Treat all test warnings as errors (#329)
* Fix gtest link issue #322. * Fix documentation erratum #325. * Increase warning level and treat warnings as errors in tests. * Remove found build issues including gtest "deprecated" warnings. * Add `LUABRIDGE_SANITIZE` option. * Refactor tests cmake file.
1 parent a08915f commit b8f423b

21 files changed

+127
-151
lines changed

.clang-format

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ DisableFormat: false
4545
ExperimentalAutoDetectBinPacking: false
4646
FixNamespaceComments: true
4747
IndentCaseLabels: false
48+
IndentPPDirectives: AfterHash
4849
IndentWidth: 4
4950
IndentWrappedFunctionNames: false
5051
KeepEmptyLinesAtTheStartOfBlocks: false

CMakeLists.txt

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,21 @@ endif()
2525

2626
add_subdirectory(Source)
2727

28-
if(LUABRIDGE_TESTING)
29-
find_package(GTest)
30-
if(NOT GTest_FOUND)
31-
set(gtest_force_shared_crt ON CACHE BOOL "Use /MD and /MDd" FORCE)
32-
add_subdirectory(third_party/gtest EXCLUDE_FROM_ALL)
33-
add_library(GTest::gtest ALIAS gtest)
34-
endif()
28+
if(LUABRIDGE_SANITIZE AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
29+
add_compile_options(-fsanitize=address)
30+
add_link_options(-fsanitize=address)
31+
endif()
3532

33+
if(LUABRIDGE_TESTING)
34+
set(gtest_force_shared_crt ON CACHE BOOL "Use /MD and /MDd" FORCE)
35+
add_subdirectory(third_party/gtest EXCLUDE_FROM_ALL)
36+
add_library(GTest::gtest ALIAS gtest)
3637
enable_testing()
3738
add_subdirectory(Tests)
3839
endif()
3940

4041
add_custom_target(Documentation SOURCES
42+
.clang-format
4143
.github/workflows/cmake.yml
4244
CHANGES.md
4345
README.md

Manual.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -870,12 +870,12 @@ <h2>2.5 - <span id="s2.5">Function Member Proxies</span></h2>
870870
</p>
871871

872872
<pre>
873-
void scale (float value)
873+
void scale (Vec* v, float value)
874874
{
875-
value->coord [0] *= value;
876-
value->coord [1] *= value;
877-
value->coord [2] *= value;
878-
};
875+
v->coord [0] *= value;
876+
v->coord [1] *= value;
877+
v->coord [2] *= value;
878+
}
879879
</pre>
880880

881881
<p>

Source/LuaBridge/Array.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ struct Stack<std::array<T, s>>
3939
luaL_error(L, "array size must be %d ", s);
4040
}
4141

42-
std::array<T, s> array;
42+
std::array<T, s> array = {};
4343

4444
int const absindex = lua_absindex(L, index);
4545
lua_pushnil(L);

Source/LuaBridge/Pair.h

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,28 +41,31 @@ struct Stack<std::pair<T1, T2>>
4141

4242
std::pair<T1, T2> pair;
4343

44-
int const absindex = lua_absindex(L, index);
44+
int const absIndex = lua_absindex(L, index);
4545
lua_pushnil(L);
4646

4747
{
48-
int const next = lua_next(L, absindex);
49-
assert(next != 0);
48+
int const hasNext = lua_next(L, lua_absindex(L, absIndex));
49+
assert(hasNext != 0);
50+
(void) hasNext;
5051

5152
pair.first = Stack<T1>::get(L, -1);
5253
lua_pop(L, 1);
5354
}
5455

5556
{
56-
int const next = lua_next(L, absindex);
57-
assert(next != 0);
57+
int const hasNext = lua_next(L, lua_absindex(L, absIndex));
58+
assert(hasNext != 0);
59+
(void) hasNext;
5860

5961
pair.second = Stack<T2>::get(L, -1);
6062
lua_pop(L, 1);
6163
}
6264

6365
{
64-
int const next = lua_next(L, absindex);
65-
assert(next == 0);
66+
int const hasNext = lua_next(L, lua_absindex(L, absIndex));
67+
assert(hasNext == 0);
68+
(void) hasNext;
6669
}
6770

6871
return pair;

Source/LuaBridge/detail/CFunctions.h

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ struct CFunc
4646
Retrieves functions from metatables and properties from propget tables.
4747
Looks through the class hierarchy if inheritance is present.
4848
*/
49-
static int indexMetaMethod(lua_State* L)
49+
static int indexMetaMethod(lua_State* L) noexcept
5050
{
5151
assert(lua_istable(L, 1) ||
5252
lua_isuserdata(L, 1)); // Stack (further not shown): table | userdata, name
@@ -112,16 +112,22 @@ struct CFunc
112112
__newindex metamethod for namespace or class static members.
113113
Retrieves properties from propset tables.
114114
*/
115-
static int newindexStaticMetaMethod(lua_State* L) { return newindexMetaMethod(L, false); }
115+
static int newindexStaticMetaMethod(lua_State* L) noexcept
116+
{
117+
return newindexMetaMethod(L, false);
118+
}
116119

117120
//----------------------------------------------------------------------------
118121
/**
119122
__newindex metamethod for non-static members.
120123
Retrieves properties from propset tables.
121124
*/
122-
static int newindexObjectMetaMethod(lua_State* L) { return newindexMetaMethod(L, true); }
125+
static int newindexObjectMetaMethod(lua_State* L) noexcept
126+
{
127+
return newindexMetaMethod(L, true);
128+
}
123129

124-
static int newindexMetaMethod(lua_State* L, bool pushSelf)
130+
static int newindexMetaMethod(lua_State* L, bool pushSelf) noexcept
125131
{
126132
assert(
127133
lua_istable(L, 1) ||
@@ -183,13 +189,18 @@ struct CFunc
183189
184190
The name of the variable is in the first upvalue.
185191
*/
186-
static int readOnlyError(lua_State* L)
192+
static int readOnlyError(lua_State* L) noexcept
187193
{
188-
std::string s;
189-
190-
s = s + "'" + lua_tostring(L, lua_upvalueindex(1)) + "' is read-only";
191-
192-
return luaL_error(L, s.c_str());
194+
try
195+
{
196+
std::string s;
197+
s = s + "'" + lua_tostring(L, lua_upvalueindex(1)) + "' is read-only";
198+
return luaL_error(L, s.c_str());
199+
}
200+
catch (...)
201+
{
202+
return luaL_error(L, "Property is read-only");
203+
}
193204
}
194205

195206
//----------------------------------------------------------------------------
@@ -308,7 +319,7 @@ struct CFunc
308319
static int f(lua_State* L)
309320
{
310321
assert(isfulluserdata(L, lua_upvalueindex(1)));
311-
typedef int (T::*MFP)(lua_State * L);
322+
typedef int (T::*MFP)(lua_State* L);
312323
T* const t = Userdata::get<T>(L, 1, false);
313324
MFP const& fnptr = *static_cast<MFP const*>(lua_touserdata(L, lua_upvalueindex(1)));
314325
assert(fnptr != 0);
@@ -322,7 +333,7 @@ struct CFunc
322333
static int f(lua_State* L)
323334
{
324335
assert(isfulluserdata(L, lua_upvalueindex(1)));
325-
typedef int (T::*MFP)(lua_State * L);
336+
typedef int (T::*MFP)(lua_State* L);
326337
T const* const t = Userdata::get<T>(L, 1, true);
327338
MFP const& fnptr = *static_cast<MFP const*>(lua_touserdata(L, lua_upvalueindex(1)));
328339
assert(fnptr != 0);

Source/LuaBridge/detail/FuncTraits.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ namespace detail {
2424
(defined(_MSC_VER) && (_MSC_VER >= 1700))
2525
// Do not define LUABRIDGE_THROWSPEC since the Xcode and gcc compilers do not
2626
// distinguish the throw specification in the function signature.
27-
#define LUABRIDGE_THROWSPEC
27+
# define LUABRIDGE_THROWSPEC
2828
#else
2929
// Visual Studio 10 and earlier pay too much mind to useless throw () spec.
3030
//
31-
#define LUABRIDGE_THROWSPEC throw()
31+
# define LUABRIDGE_THROWSPEC throw()
3232
#endif
3333

3434
//==============================================================================

Source/LuaBridge/detail/LuaHelpers.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ inline void lua_rawsetp(lua_State* L, int idx, void const* p)
3636
lua_rawset(L, idx);
3737
}
3838

39-
#define LUA_OPEQ 1
40-
#define LUA_OPLT 2
41-
#define LUA_OPLE 3
39+
# define LUA_OPEQ 1
40+
# define LUA_OPLT 2
41+
# define LUA_OPLE 3
4242

4343
inline int lua_compare(lua_State* L, int idx1, int idx2, int op)
4444
{
@@ -66,7 +66,8 @@ inline int get_length(lua_State* L, int idx)
6666
return int(lua_objlen(L, idx));
6767
}
6868

69-
#else
69+
#else // LUA_VERSION_NUM < 502
70+
7071
inline int get_length(lua_State* L, int idx)
7172
{
7273
lua_len(L, idx);
@@ -75,12 +76,12 @@ inline int get_length(lua_State* L, int idx)
7576
return len;
7677
}
7778

78-
#endif
79+
#endif // LUA_VERSION_NUM >= 502
7980

8081
#ifndef LUA_OK
81-
#define LUABRIDGE_LUA_OK 0
82+
# define LUABRIDGE_LUA_OK 0
8283
#else
83-
#define LUABRIDGE_LUA_OK LUA_OK
84+
# define LUABRIDGE_LUA_OK LUA_OK
8485
#endif
8586

8687
/** Get a table value, bypassing metamethods.

Source/LuaBridge/detail/LuaRef.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include <iostream>
1313
#include <map>
1414
#include <string>
15-
#include <vector>
1615

1716
namespace luabridge {
1817

Source/LuaBridge/detail/Namespace.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ class Namespace : public detail::Registrar
579579

580580
//--------------------------------------------------------------------------
581581
template<class U>
582-
Class<T>& addProperty(char const* name, U T::*mp, bool isWritable = true)
582+
Class<T>& addProperty(char const* name, U T::* mp, bool isWritable = true)
583583
{
584584
return addData(name, mp, isWritable);
585585
}
@@ -589,11 +589,11 @@ class Namespace : public detail::Registrar
589589
Add or replace a data member.
590590
*/
591591
template<class U>
592-
Class<T>& addData(char const* name, U T::*mp, bool isWritable = true)
592+
Class<T>& addData(char const* name, U T::* mp, bool isWritable = true)
593593
{
594594
assertStackState(); // Stack: const table (co), class table (cl), static table (st)
595595

596-
typedef const U T::*mp_t;
596+
typedef const U T::* mp_t;
597597
new (lua_newuserdata(L, sizeof(mp_t))) mp_t(mp); // Stack: co, cl, st, field ptr
598598
lua_pushcclosure(L, &CFunc::getProperty<T, U>, 1); // Stack: co, cl, st, getter
599599
lua_pushvalue(L, -1); // Stack: co, cl, st, getter, getter
@@ -1041,11 +1041,11 @@ class Namespace : public detail::Registrar
10411041
lua_newtable(L); // Stack: pns, ns, propset table (ps)
10421042
lua_rawsetp(L, -2, detail::getPropsetKey()); // ns [propsetKey] = ps. Stack: pns, ns
10431043

1044-
if (Security::hideMetatables())
1045-
{
1046-
lua_pushboolean(L, 0);
1047-
rawsetfield(L, -2, "__metatable");
1048-
}
1044+
if (Security::hideMetatables())
1045+
{
1046+
lua_pushboolean(L, 0);
1047+
rawsetfield(L, -2, "__metatable");
1048+
}
10491049

10501050
// pns [name] = ns
10511051
lua_pushvalue(L, -1); // Stack: pns, ns, ns

0 commit comments

Comments
 (0)