From 3d5c30286146e192d4c22cbb989997cdfe306200 Mon Sep 17 00:00:00 2001 From: Richard Kreckel Date: Tue, 7 Apr 2020 23:56:25 +0200 Subject: [PATCH 1/1] [PATCH] Check number of parameters when reading function from archive. Functions where looked up by their function name in archives. However, some functions have overloads for different numbers of parameters ('zeta', 'G', 'psi'). Reading archives could pick the wrong overload. Fixed by requiring that the actual number of function parameters in the archive node must equal the function's declared number of parameters. Thanks to Feng Feng for reporting this problem. --- ginac/function.cppy | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/ginac/function.cppy b/ginac/function.cppy index 2e126640..6739eb9e 100644 --- a/ginac/function.cppy +++ b/ginac/function.cppy @@ -259,18 +259,20 @@ function::function(unsigned ser, exvector && v) void function::read_archive(const archive_node& n, lst& sym_lst) { inherited::read_archive(n, sym_lst); - // Find serial number by function name + // Find serial number by function name and number of parameters + unsigned np = seq.size(); std::string s; if (n.find_string("name", s)) { unsigned int ser = 0; for (auto & it : registered_functions()) { - if (s == it.name) { + if (s == it.name && np == registered_functions()[ser].nparams) { serial = ser; return; } ++ser; } - throw (std::runtime_error("unknown function '" + s + "' in archive")); + throw (std::runtime_error("unknown function '" + s + + "' with " + std::to_string(np) + " parameters in archive")); } else throw (std::runtime_error("unnamed function in archive")); } -- 2.44.0