/* -*-c-*-
*
- * $Id: utils.c,v 1.1 2004/04/02 18:04:01 mdw Exp $
+ * $Id$
*
* Utilities for Catacomb/Perl
*
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
-/*----- Revision history --------------------------------------------------*
- *
- * $Log: utils.c,v $
- * Revision 1.1 2004/04/02 18:04:01 mdw
- * Initial checkin.
- *
- */
-
/*----- Header files ------------------------------------------------------*/
#include "catacomb-perl.h"
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 -------------------------------------------------*/