[GiNaC-list] archiving custom functions

grey_earl at web.de grey_earl at web.de
Thu Sep 30 21:33:29 CEST 2010


>Hello,
>
>> After doing a gdb backtrace, I see that it crashes on l. 310 of ex.cpp, which is
>> 
>> const ex & tmpex = other.eval(1);
>
>This sounds like a missing hold() in a user-defined function, but might
>be a GiNaC bug as well.
> 

This possibility is mentioned in the manual, yes, but I have hold() in my function. In fact, in constructing a minimal testcase I noticed that it is not the archiving of the function which fails but the archiving of a realsymbol. The testcase is attached below. Sorry for producing unrelated noise!

>
>> and it seems that GiNaC goes into an infinite loop trying to construct an expression from basic.
>> 
>> backtrace:
>> 
>> #0  GiNaC::ex::construct_from_basic (other=@0x6b4890) at ex.cpp:293
>> #1  0x0000000000416509 in GiNaC::symbol::eval (this=0x6b4890, level=1) at /usr/local/include/ginac/ex.h:255
>> #2  GiNaC::ex::construct_from_basic (other=@0x6b4890) at ex.cpp:293
>> #3  0x0000000000416509 in GiNaC::symbol::eval (this=0x6b4890, level=1) at /usr/local/include/ginac/ex.h:255
>> #4  GiNaC::ex::construct_from_basic (other=@0x6b4890) at ex.cpp:293
>> #5  0x0000000000416509 in GiNaC::symbol::eval (this=0x6b4890, level=1) at /usr/local/include/ginac/ex.h:255
>> ...
>> (at least 10k of those lines)
>
>The backtrace sort of confirms my idea, but we need the outermost
>frames to find out what's actually going on.
>
>gdb ./that/program
>
>[wait until it segfaults]
>
>bt -16
>
>and post the output here.

bt -16 gives

#392953 0x0000000000409449 in ex (other=<value optimized out>, this=<value optimized out>) at /usr/local/include/ginac/ex.h:255
#392954 GiNaC::symbol::eval (other=<value optimized out>, this=<value optimized out>) at /usr/local/include/ginac/symbol.h:49
#392955 0x00007ffff79adb66 in GiNaC::ex::construct_from_basic (other=...) at ex.cpp:310
#392956 0x0000000000409449 in ex (other=<value optimized out>, this=<value optimized out>) at /usr/local/include/ginac/ex.h:255
#392957 GiNaC::symbol::eval (other=<value optimized out>, this=<value optimized out>) at /usr/local/include/ginac/symbol.h:49
#392958 0x00007ffff79adb66 in GiNaC::ex::construct_from_basic (other=...) at ex.cpp:310
#392959 0x0000000000409449 in ex (other=<value optimized out>, this=<value optimized out>) at /usr/local/include/ginac/ex.h:255
#392960 GiNaC::symbol::eval (other=<value optimized out>, this=<value optimized out>) at /usr/local/include/ginac/symbol.h:49
#392961 0x00007ffff79adb66 in GiNaC::ex::construct_from_basic (other=...) at ex.cpp:310
#392962 0x0000000000409449 in ex (other=<value optimized out>, this=<value optimized out>) at /usr/local/include/ginac/ex.h:255
#392963 GiNaC::symbol::eval (other=<value optimized out>, this=<value optimized out>) at /usr/local/include/ginac/symbol.h:49
#392964 0x00007ffff79adb66 in GiNaC::ex::construct_from_basic (other=...) at ex.cpp:310
#392965 0x00007ffff797a3a4 in ex (other=<value optimized out>, this=<value optimized out>) at ex.h:255
#392966 GiNaC::archive_node::unarchive (other=<value optimized out>, this=<value optimized out>) at archive.cpp:543
#392967 0x00007ffff797a9f1 in GiNaC::archive::unarchive_ex (this=0x7fffffffe060, sym_lst=<value optimized out>, index=<value optimized out>)
 at archive.cpp:105
#392968 0x0000000000408937 in main () at test.cpp:33

>
>Best regards,
>	Alexei

Thanks a lot for helping! GiNaC is just great, uses way less memory than Mathematica and works just fine for me, except that archiving thing.

The testcase:

#include <iostream>
#include <fstream>
#include <stdexcept>
using namespace std;

#include <ginac/ginac.h>
using namespace GiNaC;

int main() {
 archive aro, ari;
 realsymbol r("r");
 ex test, test2;
 test = r;

 cerr << "writing archive\n";
 ofstream aus("test.gar");
 aro.archive_ex(test, "test");
 aus << aro;
 aus.close();
 cerr << "done writing archive\n";

 cerr << "reading archive\n";
 ifstream ein("test.gar");
 ein >> ari;
 ein.close();
 cerr << "done reading archive\n";
 
 lst symlst;
 symlst = r;
 
 cerr << "unarchiving\n";
 try {
 test2 = ari.unarchive_ex(symlst);
 } catch (std::exception &e) {
 cerr << e.what() << std::endl;
 }
 cerr << "recovered expression\n";

 return 0;
}
___________________________________________________________
GRATIS: Spider-Man 1-3 sowie 300 weitere Videos!
Jetzt kostenlose Movie-FLAT freischalten! http://movieflat.web.de


More information about the GiNaC-list mailing list