Charles Greathouse on Thu, 24 Nov 2016 09:42:32 +0100


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

closure_evalvoid


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.

which seems much more likely to be my broken code (esp. push_lex and set_lex which I don't seem to understand properly) than an actual bug in closure_eval.

/* 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;
}

Charles Greathouse
Case Western Reserve University