Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Math::Pari patch for 5.10.0

by syphilis (Canon)
on Mar 08, 2008 at 01:37 UTC ( #672924=perlnews: print w/ replies, xml ) Need Help??

Nicholas Clark has just posted (on p5p) a Math::Pari patch for perl 5.10.0. With this patch, Math-Pari-2.010709 builds and tests fine for me on Win32 (against pari-2.1.7), though I don't have Term-GnuPlot - so that aspect of Math::Pari remains untested (by me). For anyone interested, here is that Pari.xs patch:
--- Pari.xs (revision 2612) +++ Pari.xs (revision 2621) @@ -101,6 +101,35 @@ frame on the entry into the function for which SV is the argument. */ +#define PARI_MAGIC_TYPE ((char)0336) +#define PARI_MAGIC_PRIVATE 0x2020 + +static IV* +PARI_SV_to_IVp(SV *const sv) +{ + MAGIC *mg; + for (mg = SvMAGIC(sv); mg; mg = mg->mg_moremagic) { + if (mg->mg_type == PARI_MAGIC_TYPE + && mg->mg_private == PARI_MAGIC_PRIVATE) + return (IV *) &mg->mg_ptr; + } + assert(0); + return NULL; +} + +#define SV_to_GEN_IV(tsv) \ + ((SvTYPE(tsv) == SVt_PVAV) ? *PARI_SV_to_IVp(tsv) : SvIV(tsv)) + +#if PERL_VERSION > 9 +/* 5.9.x and later assert that you're not using SvPVX() and SvCUR() o +n arrays, + so need a little more code to cheat round this. */ +# define ARRAY_POST_59(sv) (SvTYPE(sv) == SVt_PVAV) +# define AvARRAY_set(sv, val) AvARRAY(sv) = (val) +#else +# define ARRAY_POST_59(sv) 0 +# define AvARRAY_set(sv, val) /* This will never be called. */ +#endif + #define GENmovedOffStack ((char*) 1) /* Just an atom. */ #define GENfirstOnStack ((char*) 2) /* Just an atom. */ #define GENheap NULL @@ -158,8 +187,13 @@ } \ if (isonstack(in)) { \ SV* g = SvRV(sv); \ - SvCUR(g) = oldavma - bot; \ - SvPVX(g) = (char*)PariStack; \ + if(ARRAY_POST_59(g)) { \ + AvFILLp(g) = oldavma - bot; \ + AvARRAY_set(g, (SV**)PariStack); \ + } else { \ + SvCUR(g) = oldavma - bot; \ + SvPVX(g) = (char*)PariStack; \ + } \ PariStack = g; \ perlavma = avma; \ onStack_inc; \ @@ -246,10 +280,16 @@ #endif SV *newsub = newRV_noinc((SV*)av); /* cannot use sv, it may be + sv_restore()d */ + MAGIC *mg; (void)SvUPGRADE((SV*)av, SVt_PVAV); +#if PERL_VERSION < 9 SvPVX(av) = s; - SvIVX(av) = i; +#else + AvARRAY(av) = (SV**)s; +#endif + mg = sv_magicext((SV*)av, NULL, PARI_MAGIC_TYPE, NULL, (void*)i, +0); + mg->mg_private = PARI_MAGIC_PRIVATE; sv_magic((SV*)av, newsub, 'P', Nullch, 0); SvREFCNT_dec(newsub); /* now RC(newsub)==1 */ /* We avoid an reference loop, so should be careful on DESTROY */ @@ -419,7 +459,7 @@ if (SvSTASH(tsv) == pariStash) { is_pari: { - GEN x = (GEN)SvIV(tsv); + GEN x = (GEN)SV_to_GEN_IV(tsv); if (typ(x) == t_POL /* Polynomial. */ && lgef(x)==4 /* 2 terms */ && (gcmp0((GEN)x[2])) /* Free */ @@ -435,7 +475,7 @@ /* Itsn't good to croak: $v=PARIvar 'v'; vector(3,$v,'v'); +*/ if (generate) /*croak("Same iterator in embedded PARI loop construct" +)*/; - return (entree*) SvIV(tsv); + return (entree*) SV_to_GEN_IV(tsv); } } else if (sv_derived_from(sv, "Math::Pari")) { /* Avoid recurs +ion */ if (sv_derived_from(sv, "Math::Pari::Ep")) @@ -702,13 +742,13 @@ if (SvSTASH(tsv) == pariStash) { is_pari: { - IV tmp = SvIV(tsv); + IV tmp = SV_to_GEN_IV(tsv); return (GEN) tmp; } } else if (SvSTASH(tsv) == pariEpStash) { is_pari_ep: { - IV tmp = SvIV(tsv); + IV tmp = SV_to_GEN_IV(tsv); return (GEN)(((entree*) tmp)->value); } } else if (sv_derived_from(sv, "Math::Pari")) { /* Avoid recurs +ion */ @@ -1108,6 +1148,7 @@ char *code, *s; I32 req = numargs, opt = 0; entree *ep; + MAGIC *mg; if(SvROK(cv)) cv = SvRV(cv); @@ -1150,7 +1191,9 @@ } *s = '\0'; } - ((CV*)cv)->sv_any->xof_off = numargs; /* XXXX Nasty of us... * +/ + mg = sv_magicext((SV*)cv, NULL, PARI_MAGIC_TYPE, NULL, + INT2PTR(char *, numargs), 0); + mg->mg_private = PARI_MAGIC_PRIVATE; SAVEINT(doing_PARI_autoload); doing_PARI_autoload = 1; ep = install((void*)SvREFCNT_inc(cv), name, code); @@ -1183,9 +1226,19 @@ for (sv1 = PariStack; sv1 != sv; sv1 = nextsv) { ret++; - nextsv = (SV *) SvPVX(sv1); - SvPVX(sv1) = GENmovedOffStack; /* Mark as moved off stack. */ - SvIVX(sv1) = (IV) gclone((GEN)SvIV(sv1)); + if (ARRAY_POST_59(sv1)) { + nextsv = (SV *)AvARRAY(sv1); + AvARRAY_set(sv1, (SV **)GENmovedOffStack); /* Mark as moved off s +tack. */ + } else { + nextsv = (SV *) SvPVX(sv1); + SvPVX(sv1) = GENmovedOffStack; /* Mark as moved off stack. */ + } + if(SvTYPE(sv1) == SVt_PVAV) { + IV *p = PARI_SV_to_IVp(sv1); + *p = (IV) gclone((GEN)*p); + } else { + SvIVX(sv1) = (IV) gclone((GEN)SvIV(sv1)); + } onStack_dec; offStack_inc; } @@ -1216,7 +1269,7 @@ { va_list args; SV *cv = (SV*) ep->value; - int numargs = ((CV*)cv)->sv_any->xof_off; /* XXXX Nasty of us. +.. */ + int numargs = *PARI_SV_to_IVp(cv); GEN res; int i; dSP; @@ -3738,11 +3791,13 @@ { /* PariStack keeps the latest SV that keeps a GEN on stack. */ SV* sv = SvRV(rv); - char* type = SvPVX(sv); /* The value of PariStack when the + char* type = ARRAY_POST_59(sv) ? (char *)AvARRAY(sv) : SvPVX(sv) +; + /* The value of PariStack when the * variable was created, thus the * previous SV that keeps a GEN from * stack, or some atoms. */ - long oldavma = SvCUR(sv) + bot; /* The value of avma on the entr +y + long oldavma = (ARRAY_POST_59(sv) ? AvFILLp(sv) : SvCUR(sv)) + b +ot; + /* The value of avma on the entry * to function having the SV as * argument. */ long howmany; @@ -3762,11 +3817,15 @@ AvFILLp((AV*)sv) = -1; } #endif - SvPVX(sv) = GENheap; /* To avoid extra free() in moveoff. +... */ + if (ARRAY_POST_59(sv)) { + AvARRAY_set(sv, (SV **)GENheap); + } else { + SvPVX(sv) = GENheap; /* To avoid extra free() in move +off.... */ + } if (type == GENheap) /* Leave it alone? XXXX */ /* break */ ; else if (type == GENmovedOffStack) {/* Know that it _was tempora +ry. */ - killbloc((GEN)SvIV(sv)); + killbloc((GEN)SV_to_GEN_IV(sv)); } else { /* Still on stack */ if (type != (char*)PariStack) { /* But not the newest one. * +/
Cheers,
Rob

Comment on Math::Pari patch for 5.10.0
Download Code
Re: Math::Pari patch for 5.10.0
by haoess (Curate) on Mar 08, 2008 at 11:41 UTC

    The patch applies cleanly and make runs fine, but make test doesn't:

    fw@hal:~/.cpan/build/Math-Pari-2.010709-Jg2s99$ LC_ALL=C make test cd libPARI && make LIBPERL_A="libperl.a" LINKTYPE="dynamic" OPTIMIZE=" +-O2" PREFIX="/opt/perl-33445" PASTHRU_DEFINE="" PASTHRU_INC="" make[1]: Entering directory `/home/fw/.cpan/build/Math-Pari-2.010709-J +g2s99/libPARI' make[1]: Leaving directory `/home/fw/.cpan/build/Math-Pari-2.010709-Jg +2s99/libPARI' make[1]: Entering directory `/home/fw/.cpan/build/Math-Pari-2.010709-J +g2s99/libPARI' make[1]: Nothing to be done for `all'. make[1]: Leaving directory `/home/fw/.cpan/build/Math-Pari-2.010709-Jg +2s99/libPARI' PERL_DL_NONLAZY=1 /opt/perl-33445/bin/perl5.11.0 "-MExtUtils::Command: +:MM" "-e" "test_harness(0, 'blib/lib', 'blib/arch')" t/*.t t/00_Pari..........ok t/55_analyz........ok t/55_elliptic......ok t/55_graph.........# Can't locate Term/Gnuplot.pm in @INC, ignoring pl +otting t/55_graph.........ok t/55_linear........ok t/55_nfields.......1/161 PARI: *** Warning: insufficient precision + for fundamental units, not given. t/55_nfields.......24/161 PARI: *** Warning: not a fundamental dis +criminant in quadclassunit. t/55_nfields.......ok t/55_number........ok t/55_objets........ All 62 subtests passed t/55_ploth.........# Can't locate Term/Gnuplot.pm in @INC, ignoring pl +otting t/55_ploth.........ok t/55_polyser.......ok t/55_program.......ok t/55_sumiter.......ok t/55_trans.........ok t/PlotRect.........# Can't locate Term/Gnuplot.pm in @INC, ignoring th +e test t/PlotRect.........skipped: Can't locate Term/Gnuplot.pm in @INC t/zz_leak..........ok Test Summary Report ------------------- Files=15, Tests=1245, 8 wallclock secs ( 0.26 usr 0.02 sys + 6.82 c +usr 0.09 csys = 7.19 CPU) Result: FAIL Failed 1/15 test programs. 0/1245 subtests failed. make: *** [test_dynamic] Error 255 fw@hal:~/.cpan/build/Math-Pari-2.010709-Jg2s99$ /opt/perl-33445/bin/pe +rl5.11.0 -V

    Looks strange, since there are no failing subtests.

    -- Frank

      I note you're running blead (5.11.0). The problem there might lie with something other than Math::Pari (eg Test::Harness).

      Do you have a perl-5.10.0 to try it out on ? From where does one obtain the perl-5.11.0 source ? (I can't find it anywhere, though quite a few people seem to have located it ... I'll keep looking for it.)

      Cheers,
      Rob
        I note you're running blead (5.11.0). The problem there might lie with something other than Math::Pari (eg Test::Harness).

        I get the same error with a fresh compiled 5.10 and Test::Harness 3.10.

        From where does one obtain the perl-5.11.0 source ?

        Have a look at http://dev.perl.org/perl5/source.html.

        -- Frank

        From where does one obtain the perl-5.11.0 source ? (I can't find it anywhere, though quite a few people seem to have located it ... I'll keep looking for it.)
        See perlhack (at least for the next however-many weeks until the Perforce-to-git move is done, at which time perlhack will probably be updated, but since the location of the new repo isn't determined, I don't know how to link to what will be the new perlhack :)

        Note that there has been no 5.11.0 release, but there will be at some point. Anything that calls itself 5.11.0 now is a work in progress.

Re: Math::Pari patch for 5.10.0
by Anonymous Monk on Mar 08, 2008 at 14:10 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlnews [id://672924]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (9)
As of 2014-10-20 11:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (75 votes), past polls