[GiNaC-devel] Archiving an empty container
Vladimir V. Kisil
kisilv at maths.leeds.ac.uk
Mon Sep 9 16:07:54 CEST 2019
Dear All,
There is an issue with GiNaC archiving an empty container. This
is illustrated by the code included below. The archived empty list z
is read in the expression z1 as a list with one element. Also such
code can crashes id an empty container is archived first.
The reason is in lines 215-216 of container.h: here GiNaC got
first=last for both: empty containers and containers with one element.
I propose the attached patch, which modifies the return value of
archive_node::find_last() (called at line 216 of container.h) by 1.
All other calls of archive_node::find_last() are revised to agree with
the change.
Best wishes,
Vladimir
--
Vladimir V. Kisil http://www.maths.leeds.ac.uk/~kisilv/
Book: Geometry of Mobius Transformations http://goo.gl/EaG2Vu
Software: Geometry of cycles http://moebinv.sourceforge.net/
Jupyter (Colab): https://github.com/vvkisil/MoebInv-notebooks
Jupyter (CodeOcean): http://doi.org/10.24433/CO.9934595.v2
======================================
#include <iostream>
#include <fstream>
#include <stdexcept>
#include <ginac/ginac.h>
using namespace std;
using namespace GiNaC;
int main(int argc, char** argv) {
ex x = lst{1,2}, y = lst{3}, z = lst{};
GiNaC::archive A;
A.archive_ex(x, "2elem");
A.archive_ex(y, "1elem");
A.archive_ex(z, "empty");
ofstream out("/tmp/test.gar", ios::binary);
out << A;
out.flush();
out.close();
GiNaC::archive A1;
std::ifstream ifs("/tmp/test.gar", std::ifstream::in | ios::binary);
ifs >> A1;
ex x1 = A1.unarchive_ex(lst{}, "2elem") ;
ex y1 = A1.unarchive_ex(lst{}, "1elem") ;
ex z1 = A1.unarchive_ex(lst{}, "empty") ;
x1.dbgprint(); // -> {1,2}
y1.dbgprint(); // -> {3}
z1.dbgprint(); // -> {1}
return 0;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Fix-un-archiving-of-empty-containers.patch
Type: text/x-diff
Size: 2497 bytes
Desc: Fixing archiving of empty container
URL: <http://www.ginac.de/pipermail/ginac-devel/attachments/20190909/bf445810/attachment.bin>
More information about the GiNaC-devel
mailing list