On Fri, May 14, 2004 at 09:43:03AM +0200 Rafael Garcia-Suarez wrote: > Tassilo von Parseval wrote: > > > > suppose I want to trigger external Perl subroutines but don't want to > > pass the argument via the stack but rather by setting $_. Is the > > following correct? > > > > void call_coderef (SV *coderef, char *path) { > > SV *src; > > dSP; > > > > SAVESPTR(DEFSV); > > or in other words SAVE_DEFSV
I read this in pp_grepstart: /* SAVE_DEFSV does *not* suffice here for USE_5005THREADS */ SAVESPTR(DEFSV); so I used it, too. Of course, I am not yet using pTHX_ which I probably would have to in this case. > > ENTER; > > SAVETMPS; > > PUSHMARK(SP); > > DEFSV = sv_2mortal(newSVpvn(path, strlen(path))); > > PUTBACK; > > (void) call_sv(coderef, G_DISCARD); > > > > FREETMPS; > > LEAVE; > > } > > That looks correct to me. Cool. > A caveat, though: this will not work with a lexical $_ in perl 5.9.x. > DEFSV is always $::_. With a lexical $_ (you can know whether there is > one by looking it up in the pad) you have to replace SAVE_DEFSV by > SAVESPTR(PAD_SVl(padoffset_of_dollarunderscore)). Grep bleadperl for > details. > > Hmm, maybe this means that a _new_ macro should be added for XS > writers, that get DEFSV right, by testing whether there's a lexical $_ > in scope. Opinions ? Well, yes, please! Ideally, it would be backwards-compatible so that people could already start using it now (unless of course they deliberately want $::_). Tassilo -- $_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({ pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#; $_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval