Dear GiNaCers, I found that basic::subs_one_level sometimes gives a segementation fault. This is because the branch that takes care of the no_pattern option, tries to find *this in the exmap that contains the substitution. This invokes the construction of a temporary ex from *this. If it turns out that .eval() wants to change the ex in something else, the this pointer is going to be deleted, because, presumably, it was allocated with the dynallocated flag set, by basic::subs. If no substitution is found, it is tried to return the just deleted this pointer. Not a good idea... I suggest the change below in the basic::subs_one_level function in basic.cpp. *************** *** 603,611 **** exmap::const_iterator it; if (options & subs_options::no_pattern) { ! it = m.find(*this); if (it != m.end()) return it->second; } else { for (it = m.begin(); it != m.end(); ++it) { lst repl_lst; --- 617,627 ---- exmap::const_iterator it; if (options & subs_options::no_pattern) { ! ex thisex=*this; ! it = m.find(thisex); if (it != m.end()) return it->second; + return thisex; } else { for (it = m.begin(); it != m.end(); ++it) { lst repl_lst; Best, Chris
Hi! On Mon, Sep 27, 2004 at 01:59:07PM +0200, Chris Dams wrote:
I found that basic::subs_one_level sometimes gives a segementation fault.
Do you have a test case? Bye, Christian -- / Physics is an algorithm \/ http://www.uni-mainz.de/~bauec002/
Dear Christian, On Thu, 30 Sep 2004, Christian Bauer wrote:
I found that basic::subs_one_level sometimes gives a segementation fault.
Do you have a test case?
Do you have any doubts then, after reading my description? Not that many of GiNaCs classes with a non-trivial eval method actually use basic::subs, do they? As a matter of fact, my new integral class seems to be the first. Well okay then, here is a program that needs the patch in order not to segfault on my system. In this case the integral evals into zero. #include <iostream> #include <ginac/ginac.h> using namespace std; using namespace GiNaC; int main(int argc, char** argv) { symbol x("x"),y("y"); ex f=integral(x,0,y,sin(x)); f=f.subs(y==0,subs_options::no_pattern); cout << f << endl; return 0; } Best, Chris
participants (2)
-
Chris Dams
-
Christian Bauer