Much wider support for Catacomb in all its glory.
[catacomb-perl] / mpstuff.c
index 34a5b54..9881edc 100644 (file)
--- 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));