X-Git-Url: https://git.distorted.org.uk/~mdw/catacomb-perl/blobdiff_plain/660b443cc58d4dd4e92730104429fb64d78c7075..ef3af890207c78e8352e850ed9fd510c10f7db56:/utils.c diff --git a/utils.c b/utils.c index 3d856be..e23e7ab 100644 --- a/utils.c +++ b/utils.c @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: utils.c,v 1.1 2004/04/02 18:04:01 mdw Exp $ + * $Id$ * * Utilities for Catacomb/Perl * @@ -26,14 +26,6 @@ * 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" @@ -53,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 -------------------------------------------------*/