X-Git-Url: https://git.distorted.org.uk/~mdw/catacomb-perl/blobdiff_plain/68e68e18c457d31c1c61bc08dd14a56e7e7ac21e..a1a90aaf554eb974e39e34b513747eb666180776:/utils.c diff --git a/utils.c b/utils.c index 1e72294..e23e7ab 100644 --- 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 -------------------------------------------------*/