develooper Front page | perl.perl5.porters | Postings from July 2003

How to safely clear calling stack?

Autrijus Tang
July 29, 2003 00:04
How to safely clear calling stack?
Message ID:
(CC'ing knowledgeble folks on p5p)

On Mon, Jul 21, 2003 at 04:27:28PM +0200, Jouke Visser wrote:
> The problem is fixed now. The script was mainly generated by the
> (wonderful) wxGlade tool, which includes the line
> unless (caller) {
> ...
> }
> By commenting that line, par again compiles and now the fileviewer.exe
> file runs perfectly. Maybe something for an FAQ?

This is arguably a bug -- pp-generated executables should also return an
empty caller stack to the packed program.  However I'm not quite sure
how to do it.

The problem is that at least one eval "" is needed:

    # -- cxstack_ix is now 4
    eval "print scalar caller"	# 'main'

so we need to insert something inside the eval"" to clear the caller()
stack.  I don't feel like to redefine CORE::caller unless absolutely
necessary, so this is what I came up with:

    # main.c
    XS(XS_Internals_PAR_CLEARSTACK) {
	dounwind(0); ENTER; SAVEDESTRUCTOR(exit, 0); ENTER;
    newXSproto("Internals::PAR_CLEARSTACK", XS_Internals_PAR_CLEARSTACK, "", "");

    # -- cxstack_ix is now 4
    eval "print scalar caller"	# undef

but then it segfaults and never runs the saved destructor.  Although dounwind(1)
works, it preserves the outermost caller (cxstack_ix == 1), so caller() is still

Any suggestions on how to clear it safely?

/Autrijus/ Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About