void
Call_fred()
CODE:
- PUSHMARK(sp) ;
+ PUSHMARK(SP) ;
perl_call_pv("fred", G_DISCARD|G_NOARGS) ;
fprintf(stderr, "back in Call_fred\n") ;
void
Call_fred()
CODE:
- PUSHMARK(sp) ;
+ PUSHMARK(SP) ;
perl_call_pv("fred", G_EVAL|G_DISCARD|G_NOARGS) ;
fprintf(stderr, "back in Call_fred\n") ;
{
dSP ;
- PUSHMARK(sp) ;
+ PUSHMARK(SP) ;
perl_call_pv("PrintUID", G_DISCARD|G_NOARGS) ;
}
=item 1.
-Ignore C<dSP> and C<PUSHMARK(sp)> for now. They will be discussed in
+Ignore C<dSP> and C<PUSHMARK(SP)> for now. They will be discussed in
the next example.
=item 2.
{
dSP ;
- PUSHMARK(sp) ;
+ PUSHMARK(SP) ;
XPUSHs(sv_2mortal(newSVpv(a, 0)));
XPUSHs(sv_2mortal(newSViv(b)));
PUTBACK ;
Parameters are passed to the Perl subroutine using the Perl stack.
This is the purpose of the code beginning with the line C<dSP> and
-ending with the line C<PUTBACK>.
-
+ending with the line C<PUTBACK>. The C<dSP> declares a local copy
+of the stack pointer. This local copy should B<always> be accessed
+as C<SP>.
=item 2.
ENTER ;
SAVETMPS;
- PUSHMARK(sp) ;
+ PUSHMARK(SP) ;
XPUSHs(sv_2mortal(newSViv(a)));
XPUSHs(sv_2mortal(newSViv(b)));
PUTBACK ;
ENTER ;
SAVETMPS;
- PUSHMARK(sp) ;
+ PUSHMARK(SP) ;
XPUSHs(sv_2mortal(newSViv(a)));
XPUSHs(sv_2mortal(newSViv(b)));
PUTBACK ;
ENTER ;
SAVETMPS;
- PUSHMARK(sp) ;
+ PUSHMARK(SP) ;
XPUSHs(sv_2mortal(newSViv(a)));
XPUSHs(sv_2mortal(newSViv(b)));
PUTBACK ;
sva = sv_2mortal(newSViv(a)) ;
svb = sv_2mortal(newSViv(b)) ;
- PUSHMARK(sp) ;
+ PUSHMARK(SP) ;
XPUSHs(sva);
XPUSHs(svb);
PUTBACK ;
ENTER ;
SAVETMPS;
- PUSHMARK(sp) ;
+ PUSHMARK(SP) ;
XPUSHs(sv_2mortal(newSViv(a)));
XPUSHs(sv_2mortal(newSViv(b)));
PUTBACK ;
CallSubPV(name)
char * name
CODE:
- PUSHMARK(sp) ;
+ PUSHMARK(SP) ;
perl_call_pv(name, G_DISCARD|G_NOARGS) ;
That is fine as far as it goes. The thing is, the Perl subroutine
CallSubSV(name)
SV * name
CODE:
- PUSHMARK(sp) ;
+ PUSHMARK(SP) ;
perl_call_sv(name, G_DISCARD|G_NOARGS) ;
Because we are using an SV to call I<fred> the following can all be used
void
CallSavedSub1()
CODE:
- PUSHMARK(sp) ;
+ PUSHMARK(SP) ;
perl_call_sv(rememberSub, G_DISCARD|G_NOARGS) ;
The reason this is wrong is that by the time you come to use the
void
CallSavedSub2()
CODE:
- PUSHMARK(sp) ;
+ PUSHMARK(SP) ;
perl_call_sv(keepSub, G_DISCARD|G_NOARGS) ;
To avoid creating a new SV every time C<SaveSub2> is called,
char * method
int index
CODE:
- PUSHMARK(sp);
+ PUSHMARK(SP);
XPUSHs(ref);
XPUSHs(sv_2mortal(newSViv(index))) ;
PUTBACK;
char * class
char * method
CODE:
- PUSHMARK(sp);
+ PUSHMARK(SP);
XPUSHs(sv_2mortal(newSVpv(class, 0))) ;
PUTBACK;
{
dSP ;
- PUSHMARK(sp) ;
+ PUSHMARK(SP) ;
/* Call the Perl sub to process the callback */
perl_call_sv(callback, G_DISCARD) ;
if (sv == (SV**)NULL)
croak("Internal error...\n") ;
- PUSHMARK(sp) ;
+ PUSHMARK(SP) ;
XPUSHs(sv_2mortal(newSViv(fh))) ;
XPUSHs(sv_2mortal(newSVpv(buffer, 0))) ;
PUTBACK ;
{
dSP ;
- PUSHMARK(sp) ;
+ PUSHMARK(SP) ;
XPUSHs(sv_2mortal(newSVpv(buffer, 0))) ;
PUTBACK ;
ENTER ;
SAVETMPS;
- PUSHMARK(sp) ;
+ PUSHMARK(SP) ;
XPUSHs(sv_2mortal(newSViv(a)));
XPUSHs(sv_2mortal(newSViv(b)));
PUTBACK ;
count = perl_call_pv("AddSubtract", G_ARRAY);
SPAGAIN ;
- sp -= count ;
- ax = (sp - stack_base) + 1 ;
+ SP -= count ;
+ ax = (SP - stack_base) + 1 ;
if (count != 2)
croak("Big trouble\n") ;
The code
SPAGAIN ;
- sp -= count ;
- ax = (sp - stack_base) + 1 ;
+ SP -= count ;
+ ax = (SP - stack_base) + 1 ;
sets the stack up so that we can use the C<ST> macro.