/* -*-c-*-
*
- * $Id: mpstuff.c,v 1.1 2004/04/02 18:04:01 mdw Exp $
+ * $Id$
*
* MP manipulation stuff
*
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
-/*----- Revision history --------------------------------------------------*
- *
- * $Log: mpstuff.c,v $
- * Revision 1.1 2004/04/02 18:04:01 mdw
- * Initial checkin.
- *
- */
-
/*----- Header files ------------------------------------------------------*/
#include "catacomb-perl.h"
/* --- Conversion to and from SVs --- */
-mp *mp_fromsv(SV *sv, const char *what, int radix, int keep, ...)
+mp *mp_fromsv(SV *sv, const char *what, const char *ty,
+ int radix, int keep, ...)
{
mp *m;
if (SvROK(sv)) {
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);
+ croak("%s is not of type %s", SvPVX(t), ty);
}
+ 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_MP(m); /* Kill temporary later */
+ RET(m, ty); /* Kill temporary later */
}
return (m);
}