View Single Post
Old 2012-10-28, 22:08   #10
frmky
 
frmky's Avatar
 
Jul 2003
So Cal

32·13·19 Posts
Default

I took the output of gp2c -g and added a short main function to produce
Code:
/*-*- compile-command: "cc -c -o ptest.gp.o -g -O3 -Wall -fomit-frame-pointer -fno-strict-aliasing -fPIC -I"/usr/include" ptest.gp.c && cc -o ptest.gp.so -shared -g -O3 -Wall -fomit-frame-pointer -fno-strict-aliasing -fPIC -Wl,-shared ptest.gp.o -lc -lm -L/usr/lib -lpari"; -*-*/
#include <pari/pari.h>
/*
GP;install("init_ptest","v","init_ptest","./ptest.gp.so");
GP;install("pTest","vD0,G,D0,G,","pTest","./ptest.gp.so");
*/
void init_ptest(void);
void pTest(GEN a, GEN b);
/*End of prototype*/

void
init_ptest(void)          /* void */
{
  pari_sp ltop = avma;
  avma = ltop;
  return;
}

void
pTest(GEN a, GEN b)       /* void */
{
  pari_sp ltop = avma;
  {
    pari_sp btop = avma, st_lim = stack_lim(btop, 1);
    GEN e = gen_0;
    for (e = gcopy(a); gcmp(e, b) <= 0; e = gaddgs(e, 1))
    {
      pari_printf("e is %Ps\n", e);
      if (low_stack(st_lim, stack_lim(btop, 1)))
        e = gerepilecopy(btop, e);
    }
  }
  avma = ltop;
  return;
}

int main() {
  long a, b;
  GEN x, y;
  pari_init(1000000,2);
  init_ptest();
  printf("a = ");
  scanf("%ld",&a);
  printf("b = ");
  scanf("%ld",&b);
  x = stoi(a);
  y = stoi(b);
  pTest(x, y);
  pari_close();
  return 0;
}
This I compiled with
Code:
gcc -o ptest -g -O3 -Wall -fomit-frame-pointer -fno-strict-aliasing -fPIC -I"/usr/include" ptest.gp.c -lc -lm -L/usr/lib -lpari
This runs as expected.

Last fiddled with by frmky on 2012-10-28 at 22:08
frmky is offline   Reply With Quote