Charles Greathouse on Thu, 24 Nov 2016 16:36:23 +0100 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Re: closure_evalvoid |
On Thu, Nov 24, 2016 at 03:41:57AM -0500, Charles Greathouse wrote:
> I'm having trouble using closure_evalvoid. Here is a snippet of code which
> tries to run a closure on factor(n) as n ranges from a to b. I get
>
> *** bug in closure_eval, stack underflow, please report.
Note that the stack here is the my() variable stack, not the PARI stack.
> /* a and b must be t_INTs, code must be a t_CLOSURE. */
> static int
> forfactoredss(long a, long b, GEN code)
> {
> pari_sp av = avma;
> int br = 0;
> GEN f = gnil;
> long n;
> push_lex(f,code);
> for (n = a; n <= b; n++) {
> f = Z_factor(stoi(n));
> set_lex(-1, f);
> closure_evalvoid(code);
> if (loop_break()) {
> pop_lex(1);
> br = 1;
> break;
> }
> if (get_lex(-1) != f)
> pari_err(e_MISC, "factors read-only: was changed to %Ps",
> get_lex(-1));
> }
> pop_lex(1);
> avma = av;
> return br;
> }
If loop_break() return true, then pop_lex(1) is called twice.
SInce there is one push and two pop the variable stack underflows.
Cheers,
Bill