Teach adopt() to hold the adopted pointer in custom pointer type.
[luabind.git] / test / test_super_leak.cpp
blobe2d87e2115985bb32770d54d2c1b714581db976a
1 // Copyright Daniel Wallin 2009. Use, modification and distribution is
2 // subject to the Boost Software License, Version 1.0. (See accompanying
3 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 #include "test.hpp"
7 #include <luabind/luabind.hpp>
9 struct Foo
11 static std::size_t count;
13 Foo()
15 ++count;
18 ~Foo()
20 --count;
24 std::size_t Foo::count = 0;
26 void test_main(lua_State* L)
28 using namespace luabind;
30 module(L) [
31 class_<Foo>("Foo")
32 .def(constructor<>())
35 // This used to leak the last created instance in one of the
36 // upvalues to the "super" function.
38 disable_super_deprecation();
40 DOSTRING(L,
41 "class 'Bar' (Foo)\n"
42 "function Bar.__init(self)\n"
43 " Foo.__init(self)\n"
44 "end\n"
47 DOSTRING(L,
48 "x = Bar()\n"
51 assert(Foo::count == 1);
53 DOSTRING(L,
54 "x = nil\n"
57 lua_gc(L, LUA_GCCOLLECT, 0);
59 assert(Foo::count == 0);