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

Can some Perl internals specialist give an estimate about possible memory corruption or segfaults if only a single integer scalar is changed in the signal handler?
  • Comment on Re: •Re: the unsafe signals controversy

Replies are listed 'Best First'.
Re: Re: •Re: the unsafe signals controversy
by Anonymous Monk on Mar 23, 2004 at 22:22 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.
      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.