Bill Allombert on Sun, 14 Jul 2024 19:04:54 +0200


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

Re: Should forvec_t / forvec_init() / forvec_next() work in shared library code?


On Sat, Jul 13, 2024 at 11:36:58PM +0200, hermann@stamm-wilbrandt.de wrote:
> I tried to use them today, and code stopped to work.
> I found workaround to iterate for C for() loop from 1
> until lg(points)-1 for t_VEC type GEN in libpari code:
> https://github.com/Hermann-SW/cgal4gp/blob/main/cgal4gp.cpp#L48-L53
> 
> So should  forvec_t / forvec_init() / forvec_next()  work
> when compiled with "g++  -O3 -ffp-contract=off -fno-strict-aliasing -fPIC
> …"?

Sure. Maybe you are deleting data created by forvec_init in the PARI stack that
is still in use.
Send me your code if you like, I will tell you how to fix it.

For example, this code works fine:

  {
    forvec_t iter;        /* forvec */
    GEN p1, p2, p3;       /* vec */
    p1 = cgetg(3, t_VEC);
    p2 = cgetg(3, t_VEC);
    gel(p2, 1) = gen_1;
    gel(p2, 2) = stoi(3);
    gel(p1, 1) = p2;
    p3 = cgetg(3, t_VEC);
    gel(p3, 1) = gen_2;
    gel(p3, 2) = stoi(4);
    gel(p1, 2) = p3;
    forvec_init(&iter, p1, 0);
    {
      GEN v;      /* vec */
      while ((v = forvec_next(&iter)))
        pari_printf("%Ps\n", v);
    }

Cheers,
Bill