Revert variant_callable handling to raw pointers temporarily
Since there are some issues with deploying shared_ptr fully and it has not yet been done, there's the possibility of pointers being freed twice. The raw pointer implementation results in memory leaks, but at least it should suffice until full smart pointer support can be added.
This commit is contained in:
parent
978c8d3419
commit
9fe45ce42f
5 changed files with 12 additions and 12 deletions
|
@ -96,7 +96,7 @@ public:
|
|||
private:
|
||||
variant execute(const formula_callable& variables, formula_debugger *fdb) const {
|
||||
variant var = args()[0]->evaluate(variables, fdb);
|
||||
const formula_callable* callable = var.as_callable().get();
|
||||
const formula_callable* callable = var.as_callable();
|
||||
std::vector<formula_input> inputs = callable->inputs();
|
||||
std::vector<variant> res;
|
||||
for(size_t i=0; i<inputs.size(); ++i) {
|
||||
|
@ -1509,7 +1509,7 @@ variant formula_function_expression::execute(const formula_callable& variables,
|
|||
variant var = args()[n]->evaluate(variables,fdb);
|
||||
callable.add(arg_names_[n], var);
|
||||
if(static_cast<int>(n) == star_arg_) {
|
||||
callable.set_fallback(var.as_callable().get());
|
||||
callable.set_fallback(var.as_callable());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -91,7 +91,7 @@ public:
|
|||
|
||||
const std::string& as_string() const;
|
||||
|
||||
game_logic::const_formula_callable_ptr as_callable() const
|
||||
const game_logic::formula_callable* as_callable() const
|
||||
{
|
||||
must_be(VARIANT_TYPE::TYPE_CALLABLE);
|
||||
return value_cast<game_logic::variant_callable>()->get_callable();
|
||||
|
@ -104,13 +104,13 @@ public:
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
return dynamic_cast<T*>(const_cast<game_logic::formula_callable*>(as_callable().get()));
|
||||
return dynamic_cast<T*>(const_cast<game_logic::formula_callable*>(as_callable()));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T* convert_to() const
|
||||
{
|
||||
T* res = dynamic_cast<T*>(const_cast<game_logic::formula_callable*>(as_callable().get()));
|
||||
T* res = dynamic_cast<T*>(const_cast<game_logic::formula_callable*>(as_callable()));
|
||||
if(!res) {
|
||||
throw type_error("could not convert type");
|
||||
}
|
||||
|
|
|
@ -84,9 +84,9 @@ std::string variant_callable::get_debug_string(bool verbose) const
|
|||
std::ostringstream ss;
|
||||
ss << "{";
|
||||
|
||||
if(std::find(seen_stack.begin(), seen_stack.end(), callable_.get()) == seen_stack.end()) {
|
||||
if(std::find(seen_stack.begin(), seen_stack.end(), callable_) == seen_stack.end()) {
|
||||
if(!verbose) {
|
||||
seen_stack.push_back(callable_.get());
|
||||
seen_stack.push_back(callable_);
|
||||
}
|
||||
|
||||
formula_input_vector v = callable_->inputs();
|
||||
|
@ -119,12 +119,12 @@ std::string variant_callable::get_debug_string(bool verbose) const
|
|||
|
||||
bool variant_callable::operator==(variant_value_base& other) const
|
||||
{
|
||||
return callable_->equals(value_ref_cast<variant_callable>(other).callable_.get());
|
||||
return callable_->equals(value_ref_cast<variant_callable>(other).callable_);
|
||||
}
|
||||
|
||||
bool variant_callable::operator<=(variant_value_base& other) const
|
||||
{
|
||||
return value_ref_cast<variant_callable>(other).callable_->less(callable_.get());
|
||||
return value_ref_cast<variant_callable>(other).callable_->less(callable_);
|
||||
}
|
||||
|
||||
std::string variant_string::get_serialized_string() const
|
||||
|
|
|
@ -275,7 +275,7 @@ public:
|
|||
return 1;
|
||||
}
|
||||
|
||||
const_formula_callable_ptr get_callable() const
|
||||
const formula_callable* get_callable() const
|
||||
{
|
||||
return callable_;
|
||||
}
|
||||
|
@ -308,7 +308,7 @@ private:
|
|||
*/
|
||||
static thread_local std::vector<const formula_callable*> seen_stack;
|
||||
|
||||
const_formula_callable_ptr callable_;
|
||||
const formula_callable* callable_;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -152,7 +152,7 @@ void luaW_pushfaivariant(lua_State* L, variant val) {
|
|||
luaW_pushlocation(L, loc_ref->loc());
|
||||
} else {
|
||||
// If those fail, convert generically to a map
|
||||
const formula_callable* obj = val.as_callable().get();
|
||||
const formula_callable* obj = val.as_callable();
|
||||
std::vector<formula_input> inputs;
|
||||
obj->get_inputs(&inputs);
|
||||
lua_newtable(L);
|
||||
|
|
Loading…
Add table
Reference in a new issue