You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@perl.apache.org by Stas Bekman <st...@stason.org> on 2002/03/08 09:14:48 UTC
stack question
Doug,
This kind of construct:
int mpxs_Apache__Foo_bar(pTHX_ I32 items, SV **MARK, SV **SP)
is special to WrapXS, isn't it?
you cannot really use ST() macros inside of it to access arguments on
the stack. I see that 'ax' + PL_stack_base don't point to the first
argument, but to the second one. Though MARK does point to the first
argument, so what I get is:
first arg: *MARK
second arg: *(MARK+1) == ST(0)
...
I've read through the sources and it seems that you manipulate the stack
only via MARK in this kind of mpxs_ functions.
Is this because of the second non-XSUB call from within the XS wrapper?
And ST() macros are designed only to be used inside the XSUB calls?
Thanks, Doug!
_____________________________________________________________________
Stas Bekman JAm_pH -- Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide http://perl.apache.org/guide
mailto:stas@stason.org http://ticketmaster.com http://apacheweek.com
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: stack question
Posted by Stas Bekman <st...@stason.org>.
Doug MacEachern wrote:
> On Fri, 8 Mar 2002, Stas Bekman wrote:
>
>
>>Doug,
>>
>>This kind of construct:
>>
>> int mpxs_Apache__Foo_bar(pTHX_ I32 items, SV **MARK, SV **SP)
>>
>>is special to WrapXS, isn't it?
>>
>
> dunno if i'd call it special. usage is derived from PP() functions in the
> perl core.
I meant special in a sense that you don't get the usual ST() behavior.
Inside XS() functions if you say:
dXSARGS;
ST(0) points to the first argument on the stack. Inside the function
like mpxs_Apache__Foo_bar(pTHX_ I32 items, SV **MARK, SV **SP)
plus the use of macro dAX; ST(0) returns the second element. That's why
I've asked this question in first place.
I was documenting today the possible variations on retrieving arguments
from the stack. So consider this example where I've tried to use ST()
macros, where it didn't work for me, while MARK did work.
static MP_INLINE
int mpxs_Apache__Foo_subst_sp(pTHX_ I32 items, SV **MARK, SV **SP)
{
int a, b;
if (items != 2) {
Perl_croak(aTHX_ "usage: ...");
}
a = mp_xs_sv2_int(*MARK);
b = mp_xs_sv2_int(*(MARK+1));
return a - b;
}
which simply does c=a-b, however if you add dAX and try to use ST()
macros instead of using directly MARK 'b' will receive the value
intended to 'a' and 'a' will receive garbage (most likely the 'mark'
itself). Am I doing something wrong in this example?
_____________________________________________________________________
Stas Bekman JAm_pH -- Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide http://perl.apache.org/guide
mailto:stas@stason.org http://ticketmaster.com http://apacheweek.com
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: stack question
Posted by Doug MacEachern <do...@covalent.net>.
On Fri, 8 Mar 2002, Stas Bekman wrote:
> Doug,
>
> This kind of construct:
>
> int mpxs_Apache__Foo_bar(pTHX_ I32 items, SV **MARK, SV **SP)
>
> is special to WrapXS, isn't it?
dunno if i'd call it special. usage is derived from PP() functions in the
perl core.
> you cannot really use ST() macros inside of it to access arguments on
> the stack. I see that 'ax' + PL_stack_base don't point to the first
> argument, but to the second one. Though MARK does point to the first
> argument, so what I get is:
>
> first arg: *MARK
> second arg: *(MARK+1) == ST(0)
> ...
>
> I've read through the sources and it seems that you manipulate the stack
> only via MARK in this kind of mpxs_ functions.
right.
> Is this because of the second non-XSUB call from within the XS wrapper?
> And ST() macros are designed only to be used inside the XSUB calls?
ST() could be used anywhere, the MARK/SP usage is just a little less
overhead. and this is only used for variable number of args, like
print(...):
while (MARK <= SP) {
char *buf = SvPV(*MARK, wlen);
...
MARK++;
}
if you know the number of arguments you shouldn't be using this construct.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org