X-Git-Url: https://git.distorted.org.uk/~mdw/catacomb-perl/blobdiff_plain/a24b5cfdde0be71a5bb2b85d94be3b93c7719e2a..9b46ee0d9f144189d9df836347402c3b3df97936:/mpstuff.c diff --git a/mpstuff.c b/mpstuff.c index 34a5b54..9881edc 100644 --- a/mpstuff.c +++ b/mpstuff.c @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: mpstuff.c,v 1.2 2004/04/08 01:36:21 mdw Exp $ + * $Id$ * * MP manipulation stuff * @@ -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); @@ -115,12 +126,13 @@ mp *mp_fromsv(SV *sv, const char *what, int radix, int keep, ...) m = (mp *)SvIV((SV *)SvRV(sv)); else { va_list ap; - SV *t = NEWSV(0, 0); + SV *t = sv_newmortal(); va_start(ap, keep); sv_vsetpvfn(t, what, strlen(what), &ap, 0, 0, 0); croak("%s is not of type Catacomb::MP", SvPVX(t)); - SvREFCNT_dec(t); } + if (m && keep) + MP_COPY(m); } else { if (SvIOK(sv)) m = mp_fromiv(MP_NEW, SvIV(sv));