This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Intercept assignment to $! to translate WSAExxx values to Exxx values on Windows
authorSteve Hay <steve.m.hay@googlemail.com>
Wed, 4 Sep 2013 17:20:03 +0000 (18:20 +0100)
committerSteve Hay <steve.m.hay@googlemail.com>
Mon, 16 Sep 2013 14:37:31 +0000 (15:37 +0100)
commitc9beaf974d06db3d9c7faecba5bb3e9e2a91767d
tree5f2b0168225ee392642f4996e97e679ac1ad1c61
parent80d2c56d79ef25871e30e4edd302eefe95af4b7f
Intercept assignment to $! to translate WSAExxx values to Exxx values on Windows

Since perl previously assigned WSAExxx values to $! on Windows it is quite
possible that (Perl-level) user code may also manually make similar assignments,
which will now cause breakage if the value put in $! is subsequently compared to
Errno/POSIX constants because the latter are now the corresponding Exxx values
where possible.

An example of this is in Net::Ping::tcp_connect(), which does the following to
fetch a socket-level error code:

unpack("i", getsockopt($self->{"fh"}, SOL_SOCKET, SO_ERROR))

and assigns the result (a WSAExxx value such as 10061) to $! and then goes wrong
in the subsequent test (in ping_tcp()) for $! == ECONNREFUSED (which is now 107
rather than 10061 if perl is built with VC10 or higher).

To avoid this we now intercept assignment to $! and convert any WSAExxx values
to Exxx values first.  This causes a minor oddity in that this:

perl -le "$! = 10061; print 0+$!"

will now output 107 (for VC10+ perls) but this is surely preferable to the
alternative breakage described above.
mg.c
win32/win32.c
win32/win32.h
win32/win32sck.c