X-Git-Url: https://git.distorted.org.uk/~mdw/catacomb-perl/blobdiff_plain/a1a90aaf554eb974e39e34b513747eb666180776..9b46ee0d9f144189d9df836347402c3b3df97936:/mpstuff.c diff --git a/mpstuff.c b/mpstuff.c index c891a76..9881edc 100644 --- a/mpstuff.c +++ b/mpstuff.c @@ -94,12 +94,23 @@ mp *mp_readsv(mp *m, SV *sv, STRLEN *off, int radix) return (m); } +int group_writesv(group *g, ge *x, SV *sv) +{ + mptext_svctx c; + int rc; + STRLEN len; + sv_setpvn(sv, "", 0); + c.sv = sv; + rc = G_WRITE(g, x, &mptext_svops, &c); + return (rc); +} + int mp_writesv(mp *m, SV *sv, int radix) { mptext_svctx c; int rc; STRLEN len; - SvPV(sv, len); + sv_setpvn(sv, "", 0); c.sv = sv; rc = mp_write(m, radix, &mptext_svops, &c); return (rc); @@ -107,28 +118,28 @@ int mp_writesv(mp *m, SV *sv, int radix) /* --- Conversion to and from SVs --- */ -mp *mp_fromsv(SV *sv, const char *what, const char *ty, - int radix, int keep, ...) +mp *mp_fromsv(SV *sv, const char *what, int radix, int keep, ...) { mp *m; if (SvROK(sv)) { - if (sv_derived_from(sv, "Catacomb::MP") || - sv_derived_from(sv, "Catacomb::GF")) + if (sv_derived_from(sv, "Catacomb::MP")) m = (mp *)SvIV((SV *)SvRV(sv)); else { va_list ap; SV *t = sv_newmortal(); va_start(ap, keep); sv_vsetpvfn(t, what, strlen(what), &ap, 0, 0, 0); - croak("%s is not of type %s", SvPVX(t), ty); + croak("%s is not of type Catacomb::MP", SvPVX(t)); } + if (m && keep) + MP_COPY(m); } else { if (SvIOK(sv)) m = mp_fromiv(MP_NEW, SvIV(sv)); else m = mp_readsv(MP_NEW, sv, 0, radix); if (m && !keep) - RET(m, ty); /* Kill temporary later */ + RET_MP(m); /* Kill temporary later */ } return (m); }