in reply to Re: •Re: the unsafe signals controversy
in thread the unsafe signals controversy

If the only code is $integer++, it doesn't take an "internals specialist" to realize that there is about 0 chance of memory corruption or segfaults.

Replies are listed 'Best First'.
Re: Re: Re: •Re: the unsafe signals controversy
by Anonymous Monk on Mar 23, 2004 at 22:39 UTC
    If the only code is $integer++, it doesn't take an "internals specialist" to realize that there is about 0 chance of memory corruption or segfaults.

    Wanna bet?

    Unless $integer has already just been assigned an integer value, it will currently be of type SVt_NULL; the first ++ will upgrade it to SVt_IV, which may cause a malloc. If the signal occured during a call to malloc, then Boom!

    Of course you could avoid this by ensuring that there is the initial assignment $integer=0 before the signal handler is called, but even that isn't enough. A Perl-level signal handler calls a *sub* not a statement, and entering a sub involves pushing things onto the context and save stacks, which can again trigger mallocs.