]> www.ginac.de Git - ginac.git/commitdiff
[PATCH] Check number of parameters when reading function from archive.
authorRichard Kreckel <kreckel@ginac.de>
Tue, 7 Apr 2020 21:56:25 +0000 (23:56 +0200)
committerRichard Kreckel <kreckel@ginac.de>
Tue, 7 Apr 2020 22:00:28 +0000 (00:00 +0200)
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

index 2e12664067a58c0879e7fecf3db8064668668858..6739eb9ebafdf6ebf8108e4b3a30125f0493ef78 100644 (file)
@@ -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);
 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()) {
        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;
                }
                                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"));
 }
        } else
                throw (std::runtime_error("unnamed function in archive"));
 }