Gerhard Niklasch on Tue, 24 Apr 2001 11:03:19 +0200 (MEST) |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Re: gerepilemany |
In response to: > Message-ID: <Pine.SOL.3.96.1010424093129.11505B-100000@elios> > Date: Tue, 24 Apr 2001 09:33:37 +0100 (BST) > From: Mark Chimley <M.Chimley@bristol.ac.uk> > To: pari-users@list.cr.yp.to > > I would be grateful if someone could give me a sample of how > gerepilemany should be used. There are numerous examples in the source code, in most of the files src/basemath/*.c . > I have checked my pointers and all seem > consistent with how I think the function should be used, but I get a > segmentation fault! At the time you call gerepilemany, or afterwards? The typical mistake (in my personal experience :) is forgetting to preserve something that should be preserved, and later tripping over a pointer which no longer points at useful data. Across a call to gerepilemany, the only objects on stack which are preserved are those which were created before the time avma was recorded into a local variable passed into gerepilemany's first argument, and those which are explicitly passed in the array in the second argument. Everything else is destroyed. E.g., to pick one occurrence at random, mpsqrtmod() in arith1.c essentially does: { av = avma; do a few preparatory things and create some temp objects; av1 = avma; /* actually inside a loop, but... */ lim = stack_lim(av,1); /* figure out when we want to collect garbage */ while (something or other) { do things with variables v,w,y of type GEN pointing at objects on the stack (the int, long, etc. variables do not concern us here); if (low_stack(lim, stack_lim(av,1))) { GEN *gptr[3]; gptr[0]=&y; gptr[1]=&w; gptr[2]=&v; if(DEBUGMEM>1) err(warnmem,"mpsqrtmod"); gerepilemany(av,gptr,3); } } finish off and clean up and return what needs returning; } Hope this helps, Gerhard