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

How to safely clear calling stack?

From:
Autrijus Tang
Date:
July 29, 2003 00:04
Subject:
How to safely clear calling stack?
Message ID:
20030729070422.GA10079@not.autrijus.org
(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:

    # par.pl -- 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, "", "");

    # par.pl -- 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
nonempty.

Any suggestions on how to clear it safely?

Thanks,
/Autrijus/



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About