unique expressions

Ben Sapp bsapp at nua.lampf.lanl.gov
Fri Jun 30 18:53:51 CEST 2000


Christian Bauer wrote:
> 
> Hi!
> 
> On Mon, 26 Jun 2000, Ben Sapp wrote:
> > How can I make an expresion unique?   That is, I want it to copy the
> > thing it references not just increment the reference.
> 
> This seems to do it:
> 
>   symbol x("x");
>   ex a = pow(x,2)+2*x+1;
>   ex b = *(a.bp->duplicate());

Thanks Christian.  I will try it out.  

> Why do you need this?

I use a numerical analysis program called
Octave(http://www.bevo.che.wisc.edu/octave).   I have written some
classes that are wrappers around GiNaC classes.  The wrapper classes can
be dynamically loaded into Octave which allows me to have access to some
of the power of GiNaC from within Octave.   The problem is that the
wrapper I have written for the subs routine sometimes crashes.   It
always crashes in the destructor of the symbol class.  It always give
the right answer though(even sometimes when it crashes).  Here is the
tail end of the some backtraces from gdb:

First one
----------------------------------------------
#0  0x40430ce9 in GiNaC::symbol::destroy (this=0xbffff064,
call_parent=false) at ex.h:79
#1  0x40430970 in GiNaC::symbol::~symbol (this=0xbffff064, __in_chrg=2)
at symbol.cpp:55
#2  0x402bb429 in Fsubs (args=@0xbffff190) at ../DLD-src/sym_ex.cc:331
#3  0x8216349 in octave_builtin::do_multi_index_op (this=0x860b7d8,
nargout=1, args=@0xbffff190) at ov-builtin.cc:65

Second one
-----------------------------------------------
#0  chunk_free (ar_ptr=0x40167040, p=0x8600170) at malloc.c:2985
#1  0x400d2d75 in __libc_free (mem=0x8600178) at malloc.c:2959
#2  0x83fdb17 in __builtin_delete (ptr=0x8600178) at ./cp/new2.cc:54
#3  0x40430d18 in GiNaC::symbol::destroy (this=0xbffff064,
call_parent=false) at symbol.cpp:76
#4  0x40430970 in GiNaC::symbol::~symbol (this=0xbffff064, __in_chrg=2)
at symbol.cpp:55
#5  0x402bb429 in Fsubs (args=@0xbffff190) at ../DLD-src/sym_ex.cc:331
#6  0x8216349 in octave_builtin::do_multi_index_op (this=0x860b7b0,
nargout=1, args=@0xbffff190) at ov-builtin.cc:65

Third one:
------------------------------------------------
#0  0x40430ce9 in GiNaC::symbol::destroy (this=0xbffff910,
call_parent=false) at ex.h:79
#1  0x40430970 in GiNaC::symbol::~symbol (this=0xbffff910, __in_chrg=2)
at symbol.cpp:55
#2  0x402babc1 in Fsubs (args=@0xbffffa70) at ../DLD-src/sym_ex.cc:300
#3  0x8216349 in octave_builtin::do_multi_index_op (this=0x860b348,
nargout=0, args=@0xbffffa70) at ov-builtin.cc:65

My classe declarations look something like this:

class octave_ex  : public octave_base_value
{  
 GiNaC::ex x;
  . 
  .
  .
};

The octave_base_value class also does reference counting.  I wanted to
make sure that ther was not some problems related to that.   I thought
if I always duplicated the ex variable each time it would at least tell
me that was not the problem.   


If you suspect this is a bug in GiNaC and would like to know how to
duplicate it let me know.   
It will not be easy to reproduce because you have to compile the Octave
program.  I tried to create a simple C++ program to reproduce it with no
luck.   

Thanks again,  I really appreciate your help.  

-- 
Ben Sapp                         Los Alamos National Laboratory
email: <mailto:bsapp at lanl.gov>   Phone: (505)667-3277
Fax:   (505)665-7920             URL:   http://www.neutrino.lanl.gov/
--
-
To UNSUBSCRIBE, email to ginac-list at ginac.de with a subject of "unsubscribe".



More information about the GiNaC-list mailing list