Fix crash during user_defined_conversions_2

Temporaries created during user conversion operations were being dropped
before the result of the conversion was able to be used. This fixes that
by temporarily storing the result of the conversion inside the
current Function_Push_Pop context.
This commit is contained in:
Jason Turner
2014-11-02 21:37:01 -07:00
parent 20c0e6016e
commit c876a89030
7 changed files with 103 additions and 8 deletions

View File

@@ -915,6 +915,22 @@ namespace chaiscript
m_state = t_state;
}
void save_function_params(std::initializer_list<Boxed_Value> t_params)
{
Stack_Holder &s = *m_stack_holder;
s.call_params.insert(s.call_params.begin(), std::move(t_params));
}
void save_function_params(std::vector<Boxed_Value> &&t_params)
{
Stack_Holder &s = *m_stack_holder;
for (auto &&param : t_params)
{
s.call_params.insert(s.call_params.begin(), std::move(param));
}
}
void save_function_params(const std::vector<Boxed_Value> &t_params)
{
Stack_Holder &s = *m_stack_holder;
@@ -923,7 +939,15 @@ namespace chaiscript
void new_function_call()
{
Stack_Holder &s = *m_stack_holder;
if (s.call_depth == 0)
{
m_conversions.enable_conversion_saves(true);
}
++m_stack_holder->call_depth;
save_function_params(m_conversions.take_saves());
}
void pop_function_call()
@@ -938,6 +962,7 @@ namespace chaiscript
/// \todo Critical: this needs to be smarter, memory can expand quickly
/// in tight loops involving function calls
s.call_params.clear();
m_conversions.enable_conversion_saves(false);
}
}