From: Doug MacEachern Date: Mon, 12 Feb 2001 09:22:45 +0000 (-0800) Subject: Re: [patch] context for 'U' magic functions X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=24f81a43516329e25358da5cf5b11ee0116287bd;p=p5sagit%2Fp5-mst-13.2.git Re: [patch] context for 'U' magic functions Message-ID: plus the suggestion by Nick Ing-Simmons to name the macro as PERL_MG_UFUNC to avoid namespace pollution, plus add the advice by Doug for XS writers to perl.h p4raw-id: //depot/perl@8774 --- diff --git a/mg.c b/mg.c index bb9509a..aa07283 100644 --- a/mg.c +++ b/mg.c @@ -796,7 +796,7 @@ Perl_magic_getuvar(pTHX_ SV *sv, MAGIC *mg) struct ufuncs *uf = (struct ufuncs *)mg->mg_ptr; if (uf && uf->uf_val) - (*uf->uf_val)(uf->uf_index, sv); + (*uf->uf_val)(aTHX_ uf->uf_index, sv); return 0; } @@ -1667,7 +1667,7 @@ Perl_magic_setuvar(pTHX_ SV *sv, MAGIC *mg) struct ufuncs *uf = (struct ufuncs *)mg->mg_ptr; if (uf && uf->uf_set) - (*uf->uf_set)(uf->uf_index, sv); + (*uf->uf_set)(aTHX_ uf->uf_index, sv); return 0; } diff --git a/perl.h b/perl.h index 498e6e3..df90a65 100644 --- a/perl.h +++ b/perl.h @@ -2192,11 +2192,32 @@ Gid_t getegid (void); #endif struct ufuncs { - I32 (*uf_val)(IV, SV*); - I32 (*uf_set)(IV, SV*); + I32 (*uf_val)(pTHX_ IV, SV*); + I32 (*uf_set)(pTHX_ IV, SV*); IV uf_index; }; +/* In pre-5.7-Perls the 'U' magic didn't get the thread context. + * XS code wanting to be backward compatible can do something + * like the following: + +#ifndef PERL_MG_UFUNC +/* the old way, without pTHX_ */ +#define PERL_MG_UFUNC(name,ix,sv) I32 name(IV ix, SV *sv) +#endif + +static PERL_MG_UFUNC(foo_get, index, val) +{ + sv_setsv(val, ...); + return TRUE; +} + +-- Doug MacEachern + +*/ + +#define PERL_MG_UFUNC(name,ix,sv) I32 name(pTHX_ IV ix, SV *sv) + /* Fix these up for __STDC__ */ #ifndef DONT_DECLARE_STD char *mktemp (char*);