Hello, I'd like to be able to see the perl stack from a C routine, which is in turn called from an XSUB. I'm obviously going about this the wrong way, but I'd appreciate it if someone could point out exactly how.
I have a file, foo.xs, which looks like this (ignoring the includes at the top): > void peekstack() > { > int i; > > dXSARGS; > > fprintf(stderr,"peekstack() sees %d items on the stack\n", > items); > for (i=0;i<items;i++) { > fprintf(stderr,"\t\tST(%d)=\"%s\"\n", > i,SvPV_nolen(ST(i))); > } > } > > > MODULE = foo PACKAGE = foo > > void method(...) > PREINIT: > int i; > CODE: > fprintf(stderr,"method() can see %d items on the stack\n\t", > items); > peekstack(); > fflush(stderr); What I would like is for peekstack() to be able to see exactly the same stack context as method(). However, when I run it as below, peekstack() sees a silly number of arguments on the stack. > % perl -Mblib -Mfoo -le 'for (1..3){foo->method();} > method() can see 1 items on the stack > peekstack() sees 3 items on the stack > ST(0)="1" > ST(1)="3" > ST(2)="foo" > method() can see 1 items on the stack > peekstack() sees -134 items on the stack > method() can see 1 items on the stack > peekstack() sees 3 items on the stack > ST(0)="1" > ST(1)="3" > ST(2)="foo" > % I can quite happily use PUSHMARK etc to set up a new stack context before calling peekstack(), but then it can't see the things that were passed to method(), which is what I'm after. Is there some particular macro I should be using to do this? Another (vaguely related) question:- as far as I can tell from pp.h and friends, "dXSARGS;" will actually change some internal state, by calling POPMARK. Is this the case? -jc, who does not grok the perl stack.