mirror of
https://github.com/ChaiScript/ChaiScript.git
synced 2025-12-06 16:57:04 +08:00
Fix lifetime of objects in ranged for loops
Currently this is going to incur a performance cost, but it's correct. It may need to be reevaluated. Closes #392
This commit is contained in:
parent
d5d5561d74
commit
ac0d7ce949
@ -925,10 +925,16 @@ namespace chaiscript
|
|||||||
|
|
||||||
const auto do_loop = [&loop_var_name, &t_ss, this](const auto &ranged_thing){
|
const auto do_loop = [&loop_var_name, &t_ss, this](const auto &ranged_thing){
|
||||||
try {
|
try {
|
||||||
|
for (auto &&loop_var : ranged_thing) {
|
||||||
|
// This scope push and pop might not be the best thing for perf
|
||||||
|
// but we know it's 100% correct
|
||||||
chaiscript::eval::detail::Scope_Push_Pop spp(t_ss);
|
chaiscript::eval::detail::Scope_Push_Pop spp(t_ss);
|
||||||
Boxed_Value &obj = t_ss.add_get_object(loop_var_name, void_var());
|
/// to-do make this if-constexpr with C++17 branch
|
||||||
for (auto loop_var : ranged_thing) {
|
if (!std::is_same<std::decay_t<decltype(loop_var)>, Boxed_Value>::value) {
|
||||||
obj = Boxed_Value(std::move(loop_var));
|
t_ss.add_get_object(loop_var_name, Boxed_Value(std::ref(loop_var)));
|
||||||
|
} else {
|
||||||
|
t_ss.add_get_object(loop_var_name, Boxed_Value(loop_var));
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
this->children[2]->eval(t_ss);
|
this->children[2]->eval(t_ss);
|
||||||
} catch (detail::Continue_Loop &) {
|
} catch (detail::Continue_Loop &) {
|
||||||
@ -952,10 +958,9 @@ namespace chaiscript
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const auto range_obj = call_function(range_funcs, range_expression_result);
|
const auto range_obj = call_function(range_funcs, range_expression_result);
|
||||||
chaiscript::eval::detail::Scope_Push_Pop spp(t_ss);
|
|
||||||
Boxed_Value &obj = t_ss.add_get_object(loop_var_name, void_var());
|
|
||||||
while (!boxed_cast<bool>(call_function(empty_funcs, range_obj))) {
|
while (!boxed_cast<bool>(call_function(empty_funcs, range_obj))) {
|
||||||
obj = call_function(front_funcs, range_obj);
|
chaiscript::eval::detail::Scope_Push_Pop spp(t_ss);
|
||||||
|
t_ss.add_get_object(loop_var_name, call_function(front_funcs, range_obj));
|
||||||
try {
|
try {
|
||||||
this->children[2]->eval(t_ss);
|
this->children[2]->eval(t_ss);
|
||||||
} catch (detail::Continue_Loop &) {
|
} catch (detail::Continue_Loop &) {
|
||||||
|
|||||||
@ -14,6 +14,7 @@ Current Version: 6.1.0
|
|||||||
* Support for C++17 compilers!
|
* Support for C++17 compilers!
|
||||||
* Support for UTF8 BOM #439 @AlekMosingiewicz @MarioLiebisch
|
* Support for UTF8 BOM #439 @AlekMosingiewicz @MarioLiebisch
|
||||||
|
|
||||||
|
|
||||||
### Changes since 5.8.6
|
### Changes since 5.8.6
|
||||||
|
|
||||||
*6.0.0 is a massive rework compared to 5.x. It now requires a C++14 enabled compiler*
|
*6.0.0 is a massive rework compared to 5.x. It now requires a C++14 enabled compiler*
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user