On Sat, Jan 10, 2004 at 04:48:17PM +0000 Nick Ing-Simmons wrote:

> Tassilo Parseval <[EMAIL PROTECTED]> writes:
> >Hi,
> >
> >two little questions this time.
> >
> >1) When I return multiple values from an XSUB by doing a
> >
> >    ST(0) = sv_newmortal(...);
> >    ST(1) = sv_newmortal(...);
> >    XSRETURN(2);
> >
> >do I have to do a prior EXTEND(SP, 2)? Currently I am not doing it and
> >it seems to work fine.
> 
> It depends how many args you are passed. If you have at least two args
> then at least two slots exist.

That goes along with what Nick (the other one;-) says.

> But as EXTEND is a macro and cheep if it doesn't need to do anything
> you may as well put it in.

I didn't know that EXTEND only extends on demand. Good to know.

> >2) For some parameter parsing, I'd like to get rid of a few warnings
> >that happen when I do a 'SvIV(ST(n))' and ST(n) is not SvIOK but rather
> >a string or so. 
> 
> SvIV() will upgrade a string that looks like a number
> (and indeed there is a function looks_like_a_number() you can use.)

The code in question is rather repetitive and I'd like to keep it as
short as 'int var = SvIV(ST(n))'.

> >I didn't find an interface to the warnings and so poked
> >around a little in warnings.h. Right now I'm doing it this way:
> >
> >    CODE:
> >    {
> >        SV *oldwarn = PL_curcops->cop_warnings;
> >        PL_curcops->cop_warnings = pWARN_NONE;
> >        ...
> >        PL_curcops->cop_warnings = oldwarn;
> >        XSRETURN_YES;
> >    }
> >
> >Is there a clean and commonly accepted way of doing it? 
> 
> I don't know - the above is exactly what Tk does in the one spot 
> it bothers to do anything.
> I tend to code defensively so warnings go away.

Ah, good. If it's good enough for Tk, then it's good enough for me as
well.

> >And if not, is
> >the above reliable?
> 
> The risk is if what you show as '...' can croak() - then perhaps something to 
> restore the SV would be appropriate.

That fortunately can't happen in this particular case. But om the
future, I might need something more generic, so...

> As this is an SV there is an save_item() to do the job (I think - I 
> always have to read scope.c for the save_xxx() stuff).

A 

    save_item(PL_curcops->cop_warnings);
    PL_curcops->cop_warnings = pPWARN_NONE;

would automatically restore PL_curcops->cop_warnings upon leaving the
XSUB? That would be pretty cool.

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

Reply via email to