summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Hay <steve.m.hay@googlemail.com>2011-03-18 17:04:35 -0700
committerJan Dubois <jand@activestate.com>2011-03-19 10:15:52 -0700
commitb59e75b34cef3fedd214c9b6ee744146cf8b3308 (patch)
tree5fcfe739490cbba81cc4335ecef60f8400d70e62
parent41ef34de832ea2283fbc3b35c6da583d89497204 (diff)
downloadperl-b59e75b34cef3fedd214c9b6ee744146cf8b3308.tar.gz
Redefine errno values for Visual Studio 2010
Perl traditionally stores WinSock error codes (values above 10000) in errno, with corresponding support for $! to stringify them properly. In Visual Studio 2010 (and presumably newer Windows SDKs) Microsoft has started to define additional errno constants in errno.h (values between 100 and 200) with conflicting names (e.g. EWOULDBLOCK). There are 2 ways to deal with this situation: 1) Redefine the errno.h constants back to the winsock values for the Errno and POSIX modules. 2) Translate the winsock error codes to the new errno constants in the socket implementation in win32/win32sck.c. Solution 1) has the advantage that any existing Perl code that has numeric error codes hard-coded in it will continue to work. Solution 2) has the advantage that XS code using external libaries can set errno to the new constants, and they will be handled consistently in the Perl core. It will however need additional support for other compilers and runtime libraries that don't support these new error codes. This commit implements solution 1). Blame attribution: the commit message is from Jan Dubois, the actual patch was created by Steve Hay. Signed-off-by: Jan Dubois <jand@activestate.com>
-rw-r--r--ext/Errno/Errno_pm.PL3
-rw-r--r--ext/POSIX/POSIX.xs193
-rw-r--r--win32/include/sys/socket.h4
-rw-r--r--win32/win32.h11
4 files changed, 115 insertions, 96 deletions
diff --git a/ext/Errno/Errno_pm.PL b/ext/Errno/Errno_pm.PL
index c38f309c54..56bc815002 100644
--- a/ext/Errno/Errno_pm.PL
+++ b/ext/Errno/Errno_pm.PL
@@ -229,6 +229,9 @@ sub write_errno_pm {
if ($IsMSWin32) {
print CPPI "#include <winsock.h>\n";
foreach $err (keys %wsa) {
+ print CPPI "#if defined($err) && $err >= 100\n";
+ print CPPI "#undef $err\n";
+ print CPPI "#endif\n";
print CPPI "#ifndef $err\n";
print CPPI "#define $err WSA$err\n";
print CPPI "#endif\n";
diff --git a/ext/POSIX/POSIX.xs b/ext/POSIX/POSIX.xs
index 239f0dd042..8dc1f5a308 100644
--- a/ext/POSIX/POSIX.xs
+++ b/ext/POSIX/POSIX.xs
@@ -219,124 +219,155 @@ char *tzname[] = { "" , "" };
#ifdef WIN32
/* Perl on Windows assigns WSAGetLastError() return values to errno
* (in win32/win32sck.c). Therefore we need to map these values
- * back to standard symbolic names, as long as the same name isn't
- * already defined by errno.h itself. The Errno.pm module does
- * a similar mapping.
+ * back to standard symbolic names, but only for those names having
+ * no existing value or an existing value >= 100. (VC++ 2010 defines
+ * a group of names with values >= 100 in its errno.h which we *do*
+ * need to redefine.) The Errno.pm module does a similar mapping.
*/
-# ifndef EWOULDBLOCK
-# define EWOULDBLOCK WSAEWOULDBLOCK
+# ifdef EWOULDBLOCK
+# undef EWOULDBLOCK
# endif
-# ifndef EINPROGRESS
-# define EINPROGRESS WSAEINPROGRESS
+# define EWOULDBLOCK WSAEWOULDBLOCK
+# ifdef EINPROGRESS
+# undef EINPROGRESS
# endif
-# ifndef EALREADY
-# define EALREADY WSAEALREADY
+# define EINPROGRESS WSAEINPROGRESS
+# ifdef EALREADY
+# undef EALREADY
# endif
-# ifndef ENOTSOCK
-# define ENOTSOCK WSAENOTSOCK
+# define EALREADY WSAEALREADY
+# ifdef ENOTSOCK
+# undef ENOTSOCK
# endif
-# ifndef EDESTADDRREQ
-# define EDESTADDRREQ WSAEDESTADDRREQ
+# define ENOTSOCK WSAENOTSOCK
+# ifdef EDESTADDRREQ
+# undef EDESTADDRREQ
# endif
-# ifndef EMSGSIZE
-# define EMSGSIZE WSAEMSGSIZE
+# define EDESTADDRREQ WSAEDESTADDRREQ
+# ifdef EMSGSIZE
+# undef EMSGSIZE
# endif
-# ifndef EPROTOTYPE
-# define EPROTOTYPE WSAEPROTOTYPE
+# define EMSGSIZE WSAEMSGSIZE
+# ifdef EPROTOTYPE
+# undef EPROTOTYPE
# endif
-# ifndef ENOPROTOOPT
-# define ENOPROTOOPT WSAENOPROTOOPT
+# define EPROTOTYPE WSAEPROTOTYPE
+# ifdef ENOPROTOOPT
+# undef ENOPROTOOPT
# endif
-# ifndef EPROTONOSUPPORT
-# define EPROTONOSUPPORT WSAEPROTONOSUPPORT
+# define ENOPROTOOPT WSAENOPROTOOPT
+# ifdef EPROTONOSUPPORT
+# undef EPROTONOSUPPORT
# endif
-# ifndef ESOCKTNOSUPPORT
-# define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT
+# define EPROTONOSUPPORT WSAEPROTONOSUPPORT
+# ifdef ESOCKTNOSUPPORT
+# undef ESOCKTNOSUPPORT
# endif
-# ifndef EOPNOTSUPP
-# define EOPNOTSUPP WSAEOPNOTSUPP
+# define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT
+# ifdef EOPNOTSUPP
+# undef EOPNOTSUPP
# endif
-# ifndef EPFNOSUPPORT
-# define EPFNOSUPPORT WSAEPFNOSUPPORT
+# define EOPNOTSUPP WSAEOPNOTSUPP
+# ifdef EPFNOSUPPORT
+# undef EPFNOSUPPORT
# endif
-# ifndef EAFNOSUPPORT
-# define EAFNOSUPPORT WSAEAFNOSUPPORT
+# define EPFNOSUPPORT WSAEPFNOSUPPORT
+# ifdef EAFNOSUPPORT
+# undef EAFNOSUPPORT
# endif
-# ifndef EADDRINUSE
-# define EADDRINUSE WSAEADDRINUSE
+# define EAFNOSUPPORT WSAEAFNOSUPPORT
+# ifdef EADDRINUSE
+# undef EADDRINUSE
# endif
-# ifndef EADDRNOTAVAIL
-# define EADDRNOTAVAIL WSAEADDRNOTAVAIL
+# define EADDRINUSE WSAEADDRINUSE
+# ifdef EADDRNOTAVAIL
+# undef EADDRNOTAVAIL
# endif
-# ifndef ENETDOWN
-# define ENETDOWN WSAENETDOWN
+# define EADDRNOTAVAIL WSAEADDRNOTAVAIL
+# ifdef ENETDOWN
+# undef ENETDOWN
# endif
-# ifndef ENETUNREACH
-# define ENETUNREACH WSAENETUNREACH
+# define ENETDOWN WSAENETDOWN
+# ifdef ENETUNREACH
+# undef ENETUNREACH
# endif
-# ifndef ENETRESET
-# define ENETRESET WSAENETRESET
+# define ENETUNREACH WSAENETUNREACH
+# ifdef ENETRESET
+# undef ENETRESET
# endif
-# ifndef ECONNABORTED
-# define ECONNABORTED WSAECONNABORTED
+# define ENETRESET WSAENETRESET
+# ifdef ECONNABORTED
+# undef ECONNABORTED
# endif
-# ifndef ECONNRESET
-# define ECONNRESET WSAECONNRESET
+# define ECONNABORTED WSAECONNABORTED
+# ifdef ECONNRESET
+# undef ECONNRESET
# endif
-# ifndef ENOBUFS
-# define ENOBUFS WSAENOBUFS
+# define ECONNRESET WSAECONNRESET
+# ifdef ENOBUFS
+# undef ENOBUFS
# endif
-# ifndef EISCONN
-# define EISCONN WSAEISCONN
+# define ENOBUFS WSAENOBUFS
+# ifdef EISCONN
+# undef EISCONN
# endif
-# ifndef ENOTCONN
-# define ENOTCONN WSAENOTCONN
+# define EISCONN WSAEISCONN
+# ifdef ENOTCONN
+# undef ENOTCONN
# endif
-# ifndef ESHUTDOWN
-# define ESHUTDOWN WSAESHUTDOWN
+# define ENOTCONN WSAENOTCONN
+# ifdef ESHUTDOWN
+# undef ESHUTDOWN
# endif
-# ifndef ETOOMANYREFS
-# define ETOOMANYREFS WSAETOOMANYREFS
+# define ESHUTDOWN WSAESHUTDOWN
+# ifdef ETOOMANYREFS
+# undef ETOOMANYREFS
# endif
-# ifndef ETIMEDOUT
-# define ETIMEDOUT WSAETIMEDOUT
+# define ETOOMANYREFS WSAETOOMANYREFS
+# ifdef ETIMEDOUT
+# undef ETIMEDOUT
# endif
-# ifndef ECONNREFUSED
-# define ECONNREFUSED WSAECONNREFUSED
+# define ETIMEDOUT WSAETIMEDOUT
+# ifdef ECONNREFUSED
+# undef ECONNREFUSED
# endif
-# ifndef ELOOP
-# define ELOOP WSAELOOP
+# define ECONNREFUSED WSAECONNREFUSED
+# ifdef ELOOP
+# undef ELOOP
# endif
-# ifndef ENAMETOOLONG
-# define ENAMETOOLONG WSAENAMETOOLONG
+# define ELOOP WSAELOOP
+# ifdef EHOSTDOWN
+# undef EHOSTDOWN
# endif
-# ifndef EHOSTDOWN
-# define EHOSTDOWN WSAEHOSTDOWN
+# define EHOSTDOWN WSAEHOSTDOWN
+# ifdef EHOSTUNREACH
+# undef EHOSTUNREACH
# endif
-# ifndef EHOSTUNREACH
-# define EHOSTUNREACH WSAEHOSTUNREACH
+# define EHOSTUNREACH WSAEHOSTUNREACH
+# ifdef EPROCLIM
+# undef EPROCLIM
# endif
-# ifndef ENOTEMPTY
-# define ENOTEMPTY WSAENOTEMPTY
+# define EPROCLIM WSAEPROCLIM
+# ifdef EUSERS
+# undef EUSERS
# endif
-# ifndef EPROCLIM
-# define EPROCLIM WSAEPROCLIM
+# define EUSERS WSAEUSERS
+# ifdef EDQUOT
+# undef EDQUOT
# endif
-# ifndef EUSERS
-# define EUSERS WSAEUSERS
+# define EDQUOT WSAEDQUOT
+# ifdef ESTALE
+# undef ESTALE
# endif
-# ifndef EDQUOT
-# define EDQUOT WSAEDQUOT
+# define ESTALE WSAESTALE
+# ifdef EREMOTE
+# undef EREMOTE
# endif
-# ifndef ESTALE
-# define ESTALE WSAESTALE
-# endif
-# ifndef EREMOTE
-# define EREMOTE WSAEREMOTE
-# endif
-# ifndef EDISCON
-# define EDISCON WSAEDISCON
+# define EREMOTE WSAEREMOTE
+# ifdef EDISCON
+# undef EDISCON
# endif
+# define EDISCON WSAEDISCON
#endif
typedef int SysRet;
diff --git a/win32/include/sys/socket.h b/win32/include/sys/socket.h
index a396f00584..53abf0cd21 100644
--- a/win32/include/sys/socket.h
+++ b/win32/include/sys/socket.h
@@ -82,10 +82,6 @@
extern "C" {
#endif
-#ifndef ENOTSOCK
-#define ENOTSOCK WSAENOTSOCK
-#endif
-
#ifdef USE_SOCKETS_AS_HANDLES
#ifndef PERL_FD_SETSIZE
diff --git a/win32/win32.h b/win32/win32.h
index 204a380099..4c58b8c252 100644
--- a/win32/win32.h
+++ b/win32/win32.h
@@ -525,17 +525,6 @@ void win32_wait_for_children(pTHX);
#define EXEC_ARGV_CAST(x) ((const char *const *) x)
-#if !defined(ECONNABORTED) && defined(WSAECONNABORTED)
-#define ECONNABORTED WSAECONNABORTED
-#endif
-#if !defined(ECONNRESET) && defined(WSAECONNRESET)
-#define ECONNRESET WSAECONNRESET
-#endif
-#if !defined(EAFNOSUPPORT) && defined(WSAEAFNOSUPPORT)
-#define EAFNOSUPPORT WSAEAFNOSUPPORT
-#endif
-/* Why not needed for ECONNREFUSED? --abe */
-
DllExport void *win32_signal_context(void);
#define PERL_GET_SIG_CONTEXT win32_signal_context()