From 9a798383691c4e5d6ce38dbff91897dccaa339da Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Sat, 20 Jul 2024 18:58:29 +0200 Subject: [PATCH] Bugfix for issue-1793: using the heap to properly store the default values --- src/gsi/gsi/gsiExpression.cc | 8 ++++---- src/pya/pya/pyaCallables.cc | 8 ++++---- src/rba/rba/rba.cc | 8 ++++---- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/gsi/gsi/gsiExpression.cc b/src/gsi/gsi/gsiExpression.cc index 3d77ddada..46ca33374 100644 --- a/src/gsi/gsi/gsiExpression.cc +++ b/src/gsi/gsi/gsiExpression.cc @@ -1036,10 +1036,10 @@ VariantUserClassImpl::execute_gsi (const tl::ExpressionParserContext & /*context // leave it to the consumer to establish the default values (that is faster) break; } - const tl::Variant &def_value = a->spec ()->default_value (); - // NOTE: this const_cast means we need to take care that we do not use default values on "out" parameters. - // Otherwise there is a chance we will modify the default value. - gsi::push_arg (arglist, *a, const_cast (def_value), &heap); + // Note: we will use the default value variant for longer, so push it to the heap (#1793) + tl::Variant *def_value = new tl::Variant (a->spec ()->default_value ()); + heap.push (def_value); + gsi::push_arg (arglist, *a, *def_value, &heap); } else { throw tl::Exception (tl::to_string ("No argument provided (positional or keyword) and no default value available")); } diff --git a/src/pya/pya/pyaCallables.cc b/src/pya/pya/pyaCallables.cc index 05b463f40..5422c9968 100644 --- a/src/pya/pya/pyaCallables.cc +++ b/src/pya/pya/pyaCallables.cc @@ -764,10 +764,10 @@ push_args (gsi::SerialArgs &arglist, const gsi::MethodBase *meth, PyObject *args // leave it to the consumer to establish the default values (that is faster) break; } - const tl::Variant &def_value = a->spec ()->default_value (); - // NOTE: this const_cast means we need to take care that we do not use default values on "out" parameters. - // Otherwise there is a chance we will modify the default value. - gsi::push_arg (arglist, *a, const_cast (def_value), &heap); + // Note: we will use the default value variant for longer, so push it to the heap (#1793) + tl::Variant *def_value = new tl::Variant (a->spec ()->default_value ()); + heap.push (def_value); + gsi::push_arg (arglist, *a, *def_value, &heap); } else { throw tl::Exception (tl::to_string (tr ("No argument provided (positional or keyword) and no default value available"))); } diff --git a/src/rba/rba/rba.cc b/src/rba/rba/rba.cc index e51abfeb4..21743409b 100644 --- a/src/rba/rba/rba.cc +++ b/src/rba/rba/rba.cc @@ -1125,10 +1125,10 @@ push_args (gsi::SerialArgs &arglist, const gsi::MethodBase *meth, VALUE *argv, i // leave it to the consumer to establish the default values (that is faster) break; } - const tl::Variant &def_value = a->spec ()->default_value (); - // NOTE: this const_cast means we need to take care that we do not use default values on "out" parameters. - // Otherwise there is a chance we will modify the default value. - gsi::push_arg (arglist, *a, const_cast (def_value), &heap); + // Note: we will use the default value variant for longer, so push it to the heap (#1793) + tl::Variant *def_value = new tl::Variant (a->spec ()->default_value ()); + heap.push (def_value); + gsi::push_arg (arglist, *a, *def_value, &heap); } else { throw tl::Exception (tl::to_string (tr ("No argument provided (positional or keyword) and no default value available"))); }