In perl.git, the branch smoke-me/steveh/errno has been created

<http://perl5.git.perl.org/perl.git/commitdiff/3564617cf6ed953b4b44015cc3d9de09f25fa325?hp=0000000000000000000000000000000000000000>

        at  3564617cf6ed953b4b44015cc3d9de09f25fa325 (commit)

- Log -----------------------------------------------------------------
commit 3564617cf6ed953b4b44015cc3d9de09f25fa325
Author: Steve Hay <[email protected]>
Date:   Fri Sep 6 14:25:53 2013 +0100

    Add more errno.h constants to POSIX for exporting if they exist
    
    This change adds the following constants, which are all found in errno.h in
    MS VC++ 2010 and higher:
    
    EBADMSG
    ECANCELED
    EIDRM
    EILSEQ
    ENODATA
    ENOLINK
    ENOMSG
    ENOSR
    ENOSTR
    ENOTRECOVERABLE
    ENOTSUP
    EOTHER
    EOVERFLOW
    EOWNERDEAD
    EPROTO
    ETIME

M       ext/POSIX/lib/POSIX.pm
M       ext/POSIX/t/export.t

commit 07915a136488fec8b11c28ef02a2b5482cb8b0af
Author: Steve Hay <[email protected]>
Date:   Fri Sep 6 10:17:54 2013 +0100

    Simplify errno2.h slightly
    
    There is no need for it to worry about ensuring that standard errno.h values
    like EINTR are defined.
    
    There is no point in it defining dummy constants like EINVALIDPROCTABLE 
which
    do not exist in errno.h at all. They would only be given the corresponding
    WSAExxx values anyway, so the win32sck.c function might just as well return
    them directly.
    
    Other constants like ESOCKTNOSUPPORT which do not exist in errno.h on 
Windows
    but presumably exist elsewhere since POSIX tries to exports them are still
    worth defining (where possible -- it isn't possible for EHOSTDOWN since 
there
    is no corresponding WSAEHOSTDOWN); add comments for these for clarity.
    
    Also comment which errno.h constants are new in VC10, and mention three of
    the four that win32/include/sys/socket.h used to redefine because they are
    used in the perl core (ENOTSOCK, EAFNOSUPPORT and ECONNABORTED) -- the other
    one (ECONNRESET) does not appear to be used in the perl core as far as I can
    tell.

M       win32/include/sys/errno2.h
M       win32/win32sck.c

commit ee9ba0a7856eada4ff3c5ae555e257fcbb2741af
Author: Steve Hay <[email protected]>
Date:   Thu Sep 5 15:18:20 2013 +0100

    Fix stringification of $! in VC10+ builds where errno > sys_nerr
    
    VC++ 2010 and above define a "POSIX supplement" of errno values ranging from
    EADDRINUSE (100) to EWOULDBLOCK (140), but sys_nerr is still 43 and 
strerror()
    returns "Unknown error" for them. We already avoid using strerror() if errno
    > sys_nerr, but we treat such values as Windows error codes (i.e. 
<winerror.h>
    values) and look up the corresponding system messages for them. There is no
    better plan for these POSIX supplement errno values, but they must be
    converted from <errno.h> values to <winerror.h> values first otherwise we
    will look up the wrong system message. In practice, we only expect to find
    errno > sys_nerr in the case of Windows sockets errors (we used to assign
    WSAGetLastError() to errno), so we simply convert Exxx values to WSAExxx
    values where possible, and use a default <winerror.h> value otherwise 
(namely,
    ERROR_INVALID_FUNCTION).
    
    This change fixes code such as this:
    
    perl -le "$!=107; print $!"
    
    which now outputs the expected "No connection could be made because the
    target machine actively refused it." rather than "The program stopped
    because an alternate diskette was not inserted." (in VC10+ builds).
    
    Also: Fix the spelling of ECANCELED.

M       win32/include/sys/errno2.h
M       win32/win32.c
M       win32/win32sck.c

commit 9e127853ae87a38aee3f051c28aa26a5bb57b1d7
Author: Steve Hay <[email protected]>
Date:   Wed Sep 4 18:20:03 2013 +0100

    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.

M       mg.c
M       win32/win32.c
M       win32/win32.h
M       win32/win32sck.c

commit 5b2665cc6dc08a01740ffe3ca5270b9fe916b0a1
Author: Steve Hay <[email protected]>
Date:   Tue Sep 3 22:57:46 2013 +0100

    Fix IO::Socket::connect() in the light of $! changes
    
    We now assign Exxx values rather than WSAExxx values to $! in the event of a
    sockets error if there is an Exxx value corresponding to the WSAExxx error.
    This is indeed the case for several Exxx values < 100, amongst them EINVAL 
(22),
    which corresponds to WSAEINVAL (10022), which IO::Socket::connect() has a 
test
    for.  Note that the test used a hard-coded value for WSAExxx since there 
were
    (and still are) no constants in Perl for that.  Users will now be able to 
test
    for EINVAL instead, but no existing code will be using that because it has
    always had the value 22.
    
    This non-backwards-compatible breakage seems unavoidable if we are to get 
things
    in a sane state for the future because it is really a problem with how 
things
    have long been, namely that $! was being set to winsock2.h values, but if 
there
    was a corresponding errno.h value and it was < 100 then *that* was used for 
the
    Errno/POSIX constant, so authors had no good way of testing for such $! 
values.
    The new scheme corrects that by consistently using the same values for $! 
and
    for Errno/POSIX [except in the case of third-party code setting its own 
$!/errno
    values, which will be addressed in the next commit].
    
    (Ironically, Exxx values >= 100 (the ones which caused all this trouble in 
the
    first place!) don't have this problem as long as code uses the Exxx 
constants
    rather than the hard-coded 100XX numbers.  For example, if code tests $! ==
    ECONNABORTED, where $! and ECONNABORTED were both previously set to 
winsock2.h
    values then the same test will still work, except that now $! and 
ECONNABORTED
    are both set to errno.h values in VC10+ (or both left as winsock2.h values 
upto
    VC9).  It does still break if any code is directly testing $! == 10053, but
    that's not such a problem: that's really broken code, which should be using 
the
    constant instead.)

M       dist/IO/lib/IO/Socket.pm

commit 108978b3aa708fb8b5017eeacac3f14dec448398
Author: Steve Hay <[email protected]>
Date:   Tue Sep 3 22:57:29 2013 +0100

    Fix a problem with mod_perl on Windows using VS2010+.
    
    The problem is caused by the following two commits, which sought to deal 
with
    new Exxx values (with values >= 100) in errno.h which Microsoft added in 
VS2010:
    
    
http://perl5.git.perl.org/perl.git/commit/b59e75b34cef3fedd214c9b6ee744146cf8b3308
    
http://perl5.git.perl.org/perl.git/commit/912c63ed00375338703043928cac3c740d00cc9d
    
    The former commit was mostly a patch to Errno and POSIX, together with some
    other cleaning up in win32/win32.h and win32/include/sys/socket.h; the 
latter
    commit was a fixup to win32/include/sys/socket.h which restored (more
    aggressively) the ENOTSOCK->WSAENOTSOCK redefinition and added similar
    redefinitions for ECONNABORTED, ECONNRESET and EAFNOSUPPORT.
    
    It is the latter commit which causes this little program to output
    ECONNABORTED=10053 rather than ECONNABORTED=106 as it ought to do in VC10 
(and
    higher) builds of perl:
    
    #include <windows.h>
    #include "EXTERN.h"
    #include "perl.h"
    #include "XSUB.h"
    void main(void) {
      printf("ECONNABORTED=%d\n", ECONNABORTED);
    }
    
    That change is now causing problems with mod_perl, in which the (Perl level)
    APR::Status::is_ECONNABORTED() and the (C level) 
APR_STATUS_IS_ECONNABORTED()
    which it calls are failing to recognize an aborted connection (indicated by
    error code ECONNABORTED set by Apache httpd.exe).
    
    The APR_STATUS_IS_ECONNABORTED() macro is picked up by mod_perl from APR's
    apr_errno.h:
    
    #define APR_STATUS_IS_ECONNABORTED(s)   ((s) == APR_ECONNABORTED \
                    || (s) == APR_OS_START_SYSERR + WSAECONNABORTED)
    
    where
    
    #ifdef ECONNABORTED
    #define APR_ECONNABORTED ECONNABORTED
    #else
    #define APR_ECONNABORTED   (APR_OS_START_CANONERR + 18)
    #endif
    
    When this is compiled into httpd.exe ECONNABORTED is 106 (from errno.h) and
    APR_STATUS_IS_ECONNABORTED(s) amounts to
    
    #define APR_STATUS_IS_ECONNABORTED(s) ((s) == 106 || (s) == 730053)
    
    but when compiled into APR/Status.dll ECONNABORTED is 10053 (redefined to
    WSAECONNABORTED as above) so APR_STATUS_IS_ECONNABORTED(s) then amounts to
    
    #define APR_STATUS_IS_ECONNABORTED(s) ((s) == 10053 || (s) == 730053)
    
    which doesn't pick up an error code of 106 coming from httpd.exe.
    
    This could be worked around in mod_perl by redefining ECONNABORTED and the 
other
    three back to their original errno.h values to match what httpd.exe is 
using,
    but that might just cause problems in the other direction, with those 
values no
    longer matching the values which perl.exe is using.
    
    Moreoever, this problem could affect other XS interfaces (not just 
mod_perl), so
    it really needs to be fixed in perl.
    
    This commit implements the alternative solution mentioned the commit 
message for
    the first commit cited above. (As noted in that previous commit message, 
this
    solution equally has potential problems, missing out on the advantages of 
the
    original solution implemented, namely, better backwards compatibility with 
other
    perl code having hard-coded numeric error codes, but this will be 
unavoidable if
    we want to get to a sane state.)
    
    Note that changing the $! values is an incompatible change, so should 
probably
    not be done for 5.18.x. That's unfortunate for mod_perl (and anything else
    similarly affected), but that will just have to either live with the 
breakage
    (which was introduced in 5.14.0) until 5.20.0 or else try the workaround
    mentioned above for 5.14.x, 5.16.x and 5.18.x.
    
    The main change is to use a new function throughout win32/win32sck.c to 
convert
    WSAGetLastError() values into errno.h constants before assigning to errno. 
Every
    possible WSAExxx value (as documented by MSDN) is mapped to an Exxx value,
    although it is still possible for other WSAxxx values to get assigned to 
errno
    unchanged (but that has always been the case, and any non-existent Exxx 
values
    get mapped back to WSAExxx values anyway...).
    
    We must then ensure that all of those Exxx values are defined, which is now 
done
    (in the new file, win32/include/sys/errno2.h) in a friendlier manner, being
    careful not to redefine any (specifically the new ones in VC++ 2010 and 
above)
    which already exist. The rest are defined as the WSAExxx values, as 
mentioned
    above.
    
    Finally, we need the Errno module to know about these values, which is done 
by
    having it include that same new header file to ensure that it gets the same
    definitions, rather than having to play its own games. The new header is 
also
    used in POSIX, which similarly wants definitions of as many as possible of 
its
    hard-coded list of Exxx values.

M       MANIFEST
M       ext/Errno/Errno_pm.PL
M       ext/POSIX/POSIX.xs
M       ext/POSIX/lib/POSIX.pm
A       win32/include/sys/errno2.h
M       win32/include/sys/socket.h
M       win32/win32.c
M       win32/win32sck.c
-----------------------------------------------------------------------

--
Perl5 Master Repository

Reply via email to