Key mangling, and elliptic curves.
[catacomb-perl] / utils.c
diff --git a/utils.c b/utils.c
index 1e72294..e23e7ab 100644 (file)
--- a/utils.c
+++ b/utils.c
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
- * $Id: utils.c,v 1.2 2004/04/08 01:36:21 mdw Exp $
+ * $Id$
  *
  * Utilities for Catacomb/Perl
  *
@@ -45,4 +45,24 @@ U32 findconst(const struct consttab *cc, const char *pkg, const char *name)
   croak("unknown %s constant `%s'", pkg, name);
 }
 
+void ptrtosv(SV **sv, void *p, const char *type)
+{
+  if (p)
+    sv_setref_pv(*sv, type, (void *)p);
+  else
+    *sv = &PL_sv_undef;
+}
+
+void *ptrfromsv(SV *sv, const char *type, const char *what, ...)
+{
+  if (!sv_derived_from(sv, type)) {
+    va_list ap;
+    SV *t = sv_newmortal();
+    va_start(ap, what);
+    sv_vsetpvfn(t, what, strlen(what), &ap, 0, 0, 0);      
+    croak("%s is not of type %s", SvPVX(t), type);
+  }
+  return (void *)SvIV((SV *)SvRV(sv));
+}
+
 /*----- That's all, folks -------------------------------------------------*/