Tracking LuaJIT deletion bug, but it seems to be connected to the Hash Map iterator level...? Something is wrong, here...

This commit is contained in:
ThePhD 2017-03-13 15:05:02 -04:00
parent 84554c90ea
commit 30ecd7127a
9 changed files with 129 additions and 109 deletions

2
.gitignore vendored
View File

@ -74,3 +74,5 @@ sol.pyproj
lua-5.3.3.dll
main.ilk
main.pdb
lua-5.3.4-cxx/
lua-5.3.4/

View File

@ -5,14 +5,14 @@ calling functions bound to Lua
.. note::
This abstraction assumes the function runs safely. If you expect your code to have errors (e.g., you don't always have explicit control over it or are trying to debug errors), please use :doc:`sol::protected_function<protected_function>`.
This abstraction assumes the function runs safely. If you expect your code to have errors (e.g., you don't always have explicit control over it or are trying to debug errors), please use :doc:`sol::protected_function<protected_function>` explicitly.
.. code-block:: cpp
class function : public reference;
typedef function unsafe_function;
class unsafe_function : public reference;
typedef unsafe_function function;
Function is a correct-assuming version of :doc:`protected_function<protected_function>`, omitting the need for typechecks and error handling. It is the default function type of Sol. Grab a function directly off the stack using the constructor:
Function is a correct-assuming version of :doc:`protected_function<protected_function>`, omitting the need for typechecks and error handling (thus marginally increasing speed in some cases). It is the default function type of Sol. Grab a function directly off the stack using the constructor:
.. code-block:: cpp
:caption: constructor: function

View File

@ -10,7 +10,7 @@ For the hard technical components of Lua and its ecosystem we support, here is t
what Sol supports
-----------------
* Support for Lua 5.1, 5.2, and 5.3. We achieve this through our "doc:`compatibility<compatibility>` header.
* Support for Lua 5.1, 5.2, and 5.3. We achieve this through our :doc:`compatibility<compatibility>` header.
* :doc:`Table<api/table>` support: setting values, getting values of multiple (different) types
- :doc:`Lazy evaluation<api/proxy>` for nested/chained queries
@ -147,7 +147,7 @@ notes on implementations
Plain C -
* Obviously you can do anything you want with Plain C, but the effort involved is astronomical in comparison to what frameworks offer
* Obviously you can do anything you want with Plain C, but the effort involved is astronomical in comparison to what other wrappers, libraries and frameworks offer
* Does not scale very well (in terms of developer ease of use)
* Compilation (or package manager use) is obviously required for your platform and required to use ANY of these libraries, but that's okay because all libraries need some version of Lua anyways, so you always have this!
@ -159,6 +159,7 @@ kaguya -
* Library author (satoren) is a nice guy!
* C++11/14, or boostified (which makes it C++03 compatible)
* Class registration is a bit verbose, but not as offensive as OOLua or lua-intf or others
* Constructor setting syntax is snazzy and good
Sol -

View File

@ -13,8 +13,8 @@ Note that you can obtain safety with regards to functions you bind by using the
* Turned on by default with clang++, g++ and VC++ if a basic check for building in debug mode is detected
``SOL_SAFE_FUNCTION`` triggers the following change:
* All uses of ``sol::function`` and ``sol::stack_function`` will default to ``sol::protected_function`` and ``sol::stack_protected_function``, respectively.
* Not turned on by default under any detectible compiler settings
* All uses of ``sol::function`` and ``sol::stack_function`` will default to ``sol::protected_function`` and ``sol::stack_protected_function``, respectively, rather than ``sol::unsafe_function`` and ``sol::stack_unsafe_function``.
* Not turned on by default under any detectible compiler settings: you must turn this one on manually
``SOL_CHECK_ARGUMENTS`` triggers the following changes:
* ``sol::stack::get`` (used everywhere) defaults to using ``sol::stack::check_get`` and dereferencing the argument. It uses ``sol::type_panic`` as the handler if something goes wrong.

View File

@ -328,6 +328,11 @@ namespace sol {
template<typename... Args, typename... Fxs>
simple_usertype_metatable(lua_State* L, constructor_wrapper<Fxs...> constructorlist, Args&&... args) : simple_usertype_metatable(L, usertype_detail::check_destructor_tag(), std::forward<Args>(args)..., "new", constructorlist) {}
simple_usertype_metatable(const simple_usertype_metatable&) = default;
simple_usertype_metatable(simple_usertype_metatable&&) = default;
simple_usertype_metatable& operator=(const simple_usertype_metatable&) = default;
simple_usertype_metatable& operator=(simple_usertype_metatable&&) = default;
virtual int push_um(lua_State* L) override {
return stack::push(L, std::move(*this));
}

View File

@ -348,12 +348,12 @@ namespace sol {
template<typename T>
state_view& set_usertype(usertype<T>& user) {
return set_usertype(usertype_traits<T>::name(), user);
return set_usertype(usertype_traits<T>::name(), std::move(user));
}
template<typename Key, typename T>
state_view& set_usertype(Key&& key, usertype<T>& user) {
global.set_usertype(std::forward<Key>(key), user);
global.set_usertype(std::forward<Key>(key), std::move(user));
return *this;
}

View File

@ -263,7 +263,7 @@ namespace sol {
template<typename Class, typename... Args>
basic_table_core& new_usertype(const std::string& name, Args&&... args) {
usertype<Class> utype(std::forward<Args>(args)...);
set_usertype(name, utype);
set_usertype(name, std::move(utype));
return *this;
}
@ -276,7 +276,7 @@ namespace sol {
template<typename Class, typename... CArgs, typename... Args>
basic_table_core& new_usertype(const std::string& name, constructors<CArgs...> ctor, Args&&... args) {
usertype<Class> utype(ctor, std::forward<Args>(args)...);
set_usertype(name, utype);
set_usertype(name, std::move(utype));
return *this;
}

View File

@ -1,97 +1,99 @@
// The MIT License (MIT)
// Copyright (c) 2013-2016 Rapptz, ThePhD and contributors
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
// the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
// the Software, and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#ifndef SOL_USERTYPE_HPP
#define SOL_USERTYPE_HPP
#include "stack.hpp"
#include "usertype_metatable.hpp"
#include "simple_usertype_metatable.hpp"
#include "container_usertype_metatable.hpp"
#include <memory>
namespace sol {
template<typename T>
class usertype {
private:
std::unique_ptr<usertype_detail::registrar, detail::deleter> metatableregister;
template<typename... Args>
usertype(usertype_detail::verified_tag, Args&&... args) : metatableregister(detail::make_unique_deleter<usertype_metatable<T, std::make_index_sequence<sizeof...(Args) / 2>, Args...>, detail::deleter>(std::forward<Args>(args)...)) {}
template<typename... Args>
usertype(usertype_detail::add_destructor_tag, Args&&... args) : usertype(usertype_detail::verified, std::forward<Args>(args)..., "__gc", default_destructor) {}
template<typename... Args>
usertype(usertype_detail::check_destructor_tag, Args&&... args) : usertype(meta::condition<meta::all<std::is_destructible<T>, meta::neg<usertype_detail::has_destructor<Args...>>>, usertype_detail::add_destructor_tag, usertype_detail::verified_tag>(), std::forward<Args>(args)...) {}
public:
template<typename... Args>
usertype(Args&&... args) : usertype(meta::condition<meta::all<std::is_default_constructible<T>, meta::neg<usertype_detail::has_constructor<Args...>>>, decltype(default_constructor), usertype_detail::check_destructor_tag>(), std::forward<Args>(args)...) {}
template<typename... Args, typename... CArgs>
usertype(constructors<CArgs...> constructorlist, Args&&... args) : usertype(usertype_detail::check_destructor_tag(), std::forward<Args>(args)..., "new", constructorlist) {}
template<typename... Args, typename... Fxs>
usertype(constructor_wrapper<Fxs...> constructorlist, Args&&... args) : usertype(usertype_detail::check_destructor_tag(), std::forward<Args>(args)..., "new", constructorlist) {}
template<typename... Args>
usertype(simple_tag, lua_State* L, Args&&... args) : metatableregister(detail::make_unique_deleter<simple_usertype_metatable<T>, detail::deleter>(L, std::forward<Args>(args)...)) {}
usertype_detail::registrar* registrar_data() {
return metatableregister.get();
}
int push(lua_State* L) {
return metatableregister->push_um(L);
}
};
template<typename T>
class simple_usertype : public usertype<T> {
private:
typedef usertype<T> base_t;
lua_State* state;
public:
template<typename... Args>
simple_usertype(lua_State* L, Args&&... args) : base_t(simple, L, std::forward<Args>(args)...), state(L) {}
template <typename N, typename F>
void set(N&& n, F&& f) {
auto meta = static_cast<simple_usertype_metatable<T>*>(base_t::registrar_data());
meta->add(state, n, f);
}
};
namespace stack {
template<typename T>
struct pusher<usertype<T>> {
static int push(lua_State* L, usertype<T>& user) {
return user.push(L);
}
};
} // stack
} // sol
#endif // SOL_USERTYPE_HPP
// The MIT License (MIT)
// Copyright (c) 2013-2016 Rapptz, ThePhD and contributors
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
// the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
// the Software, and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#ifndef SOL_USERTYPE_HPP
#define SOL_USERTYPE_HPP
#include "stack.hpp"
#include "usertype_metatable.hpp"
#include "simple_usertype_metatable.hpp"
#include "container_usertype_metatable.hpp"
#include <memory>
namespace sol {
template<typename T>
class usertype {
private:
std::unique_ptr<usertype_detail::registrar, detail::deleter> metatableregister;
template<typename... Args>
usertype(usertype_detail::verified_tag, Args&&... args) : metatableregister(detail::make_unique_deleter<usertype_metatable<T, std::make_index_sequence<sizeof...(Args) / 2>, Args...>, detail::deleter>(std::forward<Args>(args)...)) {}
template<typename... Args>
usertype(usertype_detail::add_destructor_tag, Args&&... args) : usertype(usertype_detail::verified, std::forward<Args>(args)..., "__gc", default_destructor) {}
template<typename... Args>
usertype(usertype_detail::check_destructor_tag, Args&&... args) : usertype(meta::condition<meta::all<std::is_destructible<T>, meta::neg<usertype_detail::has_destructor<Args...>>>, usertype_detail::add_destructor_tag, usertype_detail::verified_tag>(), std::forward<Args>(args)...) {}
public:
template<typename... Args>
usertype(Args&&... args) : usertype(meta::condition<meta::all<std::is_default_constructible<T>, meta::neg<usertype_detail::has_constructor<Args...>>>, decltype(default_constructor), usertype_detail::check_destructor_tag>(), std::forward<Args>(args)...) {}
template<typename... Args, typename... CArgs>
usertype(constructors<CArgs...> constructorlist, Args&&... args) : usertype(usertype_detail::check_destructor_tag(), std::forward<Args>(args)..., "new", constructorlist) {}
template<typename... Args, typename... Fxs>
usertype(constructor_wrapper<Fxs...> constructorlist, Args&&... args) : usertype(usertype_detail::check_destructor_tag(), std::forward<Args>(args)..., "new", constructorlist) {}
template<typename... Args>
usertype(simple_tag, lua_State* L, Args&&... args) : metatableregister(detail::make_unique_deleter<simple_usertype_metatable<T>, detail::deleter>(L, std::forward<Args>(args)...)) {}
usertype_detail::registrar* registrar_data() {
return metatableregister.get();
}
int push(lua_State* L) {
int r = metatableregister->push_um(L);
metatableregister = nullptr;
return r;
}
};
template<typename T>
class simple_usertype : public usertype<T> {
private:
typedef usertype<T> base_t;
lua_State* state;
public:
template<typename... Args>
simple_usertype(lua_State* L, Args&&... args) : base_t(simple, L, std::forward<Args>(args)...), state(L) {}
template <typename N, typename F>
void set(N&& n, F&& f) {
auto meta = static_cast<simple_usertype_metatable<T>*>(base_t::registrar_data());
meta->add(state, n, f);
}
};
namespace stack {
template<typename T>
struct pusher<usertype<T>> {
static int push(lua_State* L, usertype<T>& user) {
return user.push(L);
}
};
} // stack
} // sol
#endif // SOL_USERTYPE_HPP

View File

@ -138,6 +138,11 @@ namespace sol {
}
struct registrar {
registrar() = default;
registrar(const registrar&) = default;
registrar(registrar&&) = default;
registrar& operator=(const registrar&) = default;
registrar& operator=(registrar&&) = default;
virtual int push_um(lua_State* L) = 0;
virtual ~registrar() {}
};
@ -439,6 +444,11 @@ namespace sol {
mapping.insert(ilist);
}
usertype_metatable(const usertype_metatable&) = default;
usertype_metatable(usertype_metatable&&) = default;
usertype_metatable& operator=(const usertype_metatable&) = default;
usertype_metatable& operator=(usertype_metatable&&) = default;
template <std::size_t I0, std::size_t I1, bool is_index>
static int real_find_call(lua_State* L, void* um, int) {
auto& f = *static_cast<usertype_metatable*>(um);