Folks,
This does not work (<= is include): winsock.h <= sys/types.h <= sys/select.h
BANG! FD_CLR gets defined before we have a chance to manipulate it.
Any ideas on how to fix this?
On Wed, 18 Dec 2002, Dimitrie O. Paun wrote:
Folks,
This does not work (<= is include): winsock.h <= sys/types.h <= sys/select.h
BANG! FD_CLR gets defined before we have a chance to manipulate it.
Any ideas on how to fix this?
I assume this is for Winelib. Then here are your choices as I see them:
* if you want maximum compatibility, then use the msvcrt headers. Then you will not have that problem.
* if you want to use the regular Unix headers, then the price will be a tinybit of reordering of the #includes so that sys/types.h gets included after sys/types.h and that should work too.
Unfortunately I don't think there is any other solution.
Or did you really mean that winsock.h includes sys/types.h which then includes sys/select.h which defines FD_CLR? If that's the case then a bit of reordering of code in winsock.h should solve the problem.`
On December 18, 2002 03:28 am, Francois Gouget wrote:
Or did you really mean that winsock.h includes sys/types.h which then includes sys/select.h which defines FD_CLR? If that's the case then a bit of reordering of code in winsock.h should solve the problem.`
Indeed, that is the problem. At line 60 in include/winsock.h we have:
#ifndef __WINE_USE_MSVCRT /* Get the u_xxx types from the Unix headers. They will do and doing it * this way will avoid redefinitions. But on FreeBSD we may get macros * and prototypes for htonl & co. This means the functions will not be * called because of the macros. So this should not harm us too much unless * we try to define our own prototypes (different calling convention). */ # include <sys/types.h>
So this seems to try to solve the problem, but it is the very thing that causes it. It looks like you tried to make winsock.h work together with the Unix headers, so any insight into this problem will be highly appreciated.
On December 18, 2002 03:28 am, Francois Gouget wrote:
- if you want maximum compatibility, then use the msvcrt headers. Then
you will not have that problem.
To clarify this point: this app (actually library: wxWindows) when compiled under MinGW expects stuff in headers that are not present in msvcrt headers (such as gethostname()). So, for maximum compatibility, we need to support native Unix headers. :)
On Wed, 18 Dec 2002, Dimitrie O. Paun wrote:
On December 18, 2002 03:28 am, Francois Gouget wrote:
- if you want maximum compatibility, then use the msvcrt headers. Then
you will not have that problem.
To clarify this point: this app (actually library: wxWindows) when compiled under MinGW expects stuff in headers that are not present in msvcrt headers (such as gethostname()). So, for maximum compatibility, we need to support native Unix headers. :)
This seems a bit strange. So you say that on Linux sys/types.h causes FD_CLR to be defined. That was not the case last time I checked (admitedly months ago). Maybe it's a new glibc or gcc thing? (ok, checked, it is the case :-( that's new)
The goal of the FD_CLR check was to 'gracefully' deal with source files that do:
#include <stdlib.h> #include <windows.h>
This would cause FD_CLR and more importantly fd_set, timeval and select to already be defined with incompatible types/prototypes.
So, back to the sys/types.h issue. We apparently very much self-trigger the same issue with sys/types.h. So I'll move the FD_CLR section and post a patch.
On Wed, 18 Dec 2002, Dimitrie O. Paun wrote:
Folks,
This does not work (<= is include): winsock.h <= sys/types.h <= sys/select.h
BANG! FD_CLR gets defined before we have a chance to manipulate it.
Any ideas on how to fix this?
Does this work? There might still be problems with FreeBSD but I did not have time to check today...
Index: include/winsock.h =================================================================== RCS file: /home/wine/wine/include/winsock.h,v retrieving revision 1.49 diff -u -r1.49 winsock.h --- include/winsock.h 21 Nov 2002 23:44:19 -0000 1.49 +++ include/winsock.h 20 Dec 2002 01:14:39 -0000 @@ -56,29 +56,83 @@ /* * This section defines the items that conflict with the Unix headers. */ +#if !defined(USE_WS_PREFIX) && !defined(__WINE_USE_MSVCRT) +/* We are not using the WS_ prefix and not using the MSVCRT either so we + * risk getting conflicts for everything related to select. + */ +# ifdef FD_CLR +/* Too late, the Unix version of stdlib.h was included before winsock.h. + * This means select and all the related stuff is already defined and we + * cannot override types and function prototypes. + * All we can do is disable all these symbols so that they are not used + * inadvertantly. + */ +# undef FD_SETSIZE +# undef FD_CLR +# undef FD_SET +# undef FD_ZERO +# undef FD_ISSET
-#ifndef __WINE_USE_MSVCRT -/* Get the u_xxx types from the Unix headers. They will do and doing it - * this way will avoid redefinitions. But on FreeBSD we may get macros - * and prototypes for htonl & co. This means the functions will not be - * called because of the macros. So this should not harm us too much unless - * we try to define our own prototypes (different calling convention). +# define FD_SETSIZE Include_winsock_h_before_stdlib_h_or_use_the_MSVCRT_library +# define FD_CLR Include_winsock_h_before_stdlib_h_or_use_the_MSVCRT_library +# define FD_SET Include_winsock_h_before_stdlib_h_or_use_the_MSVCRT_library +# define FD_ZERO Include_winsock_h_before_stdlib_h_or_use_the_MSVCRT_library +# define FD_ISSET Include_winsock_h_before_stdlib_h_or_use_the_MSVCRT_library +# define fd_set Include_winsock_h_before_stdlib_h_or_use_the_MSVCRT_library +# define select Include_winsock_h_before_stdlib_h_or_use_the_MSVCRT_library +# include <sys/types.h> +# ifdef __MINGW_H + /* MinGW doesn't define the u_xxx types */ +# define WS_DEFINE_U_TYPES +# endif +# else +/* stdlib.h has not been included yet so it's not too late. Include it now + * making sure that none of the select symbols is affected. Then we can + * define them with our own values. */ +# define fd_set unix_fd_set +# define timeval unix_timeval +# define select unix_select +# include <sys/types.h> +# ifndef FD_CLR + /* On Windows-style platforms, sys/types.h does not define FD_CLR + * and does not define the u_xxx types + */ +# define WS_DEFINE_U_TYPES +# endif +# undef fd_set +# undef timeval +# undef select +# undef FD_SETSIZE +# undef FD_CLR +# undef FD_SET +# undef FD_ZERO +# undef FD_ISSET + +# define WS_DEFINE_SELECT +# endif /* FD_CLR */ + +#elif !defined(__WINE_USE_MSVCRT) +# define WS_DEFINE_SELECT # include <sys/types.h> -# if defined(USE_WS_PREFIX) || !defined(htonl) -# define WS_DEFINE_HTONL -# endif /* htonl */ +# ifndef FD_CLR + /* On Windows-style platforms, sys/types.h does not define FD_CLR + * and does not define the u_xxx types + */ +# define WS_DEFINE_U_TYPES +# endif #else -/* Since we are using the MSVCRT headers, we must define the u_xxx - * types ourselves. - */ +# define WS_DEFINE_SELECT + /* Our MSVCRT headers don't define the u_xxx types */ +# define WS_DEFINE_U_TYPES +#endif /* !USE_WS_PREFIX && !__WINE_USE_MSVCRT */ + +#ifdef WS_DEFINE_U_TYPES typedef unsigned char u_char; typedef unsigned short u_short; typedef unsigned int u_int; typedef unsigned long u_long; -# define WS_DEFINE_HTONL -#endif /* __WINE_USE_MSVCRT */ - +#endif
/* @@ -349,55 +403,6 @@ * Select */
-#if !defined(USE_WS_PREFIX) && !defined(__WINE_USE_MSVCRT) -/* We are not using the WS_ prefix and not using the MSVCRT either so we - * risk getting conflicts for everything related to select. - */ -# ifdef FD_CLR -/* Too late, the Unix version of stdlib.h was included before winsock.h. - * This means select and all the related stuff is already defined and we - * cannot override types and function prototypes. - * All we can do is disable all these symbols so that they are not used - * inadvertantly. - */ -# undef FD_SETSIZE -# undef FD_CLR -# undef FD_SET -# undef FD_ZERO -# undef FD_ISSET - -# define FD_SETSIZE Include_winsock_h_before_stdlib_h_or_use_the_MSVCRT_library -# define FD_CLR Include_winsock_h_before_stdlib_h_or_use_the_MSVCRT_library -# define FD_SET Include_winsock_h_before_stdlib_h_or_use_the_MSVCRT_library -# define FD_ZERO Include_winsock_h_before_stdlib_h_or_use_the_MSVCRT_library -# define FD_ISSET Include_winsock_h_before_stdlib_h_or_use_the_MSVCRT_library -# define fd_set Include_winsock_h_before_stdlib_h_or_use_the_MSVCRT_library -# define select Include_winsock_h_before_stdlib_h_or_use_the_MSVCRT_library -# else -/* stdlib.h has not been included yet so it's not too late. Include it now - * making sure that none of the select symbols is affected. Then we can - * define them with our own values. - */ -# define fd_set unix_fd_set -# define timeval unix_timeval -# define select unix_select -# include <stdlib.h> -# undef fd_set -# undef timeval -# undef select -# undef FD_SETSIZE -# undef FD_CLR -# undef FD_SET -# undef FD_ZERO -# undef FD_ISSET - -# define WS_DEFINE_SELECT -# endif /* FD_CLR */ - -#else -# define WS_DEFINE_SELECT -#endif /* !USE_WS_PREFIX && !__WINE_USE_MSVCRT */ - #ifdef WS_DEFINE_SELECT /* Define our own version of select and the associated types and macros */
@@ -929,12 +934,16 @@ int WINAPI WS(shutdown)(SOCKET,int); SOCKET WINAPI WS(socket)(int,int,int);
-#ifdef WS_DEFINE_HTONL +#if defined(htonl) && !defined(USE_WS_PREFIX) +# undef htonl +# undef htons +# undef ntohl +# undef ntohs +#endif u_long WINAPI WS(htonl)(u_long); u_short WINAPI WS(htons)(u_short); u_long WINAPI WS(ntohl)(u_long); u_short WINAPI WS(ntohs)(u_short); -#endif
#if defined(__WINE__) || !defined(__WINE_WINSOCK2__) /* Stuff specific to winsock.h */
On December 20, 2002 02:07 am, Francois Gouget wrote:
Does this work?
It might, but if I try to compile with the glibc headers, I get other problems not in that _stricmp, and _strdup are not declared. Which is odd, as I seem to have compiled with glibc headers a few files before...
It's way past my bed time, I'll into it tomorrow.
On December 20, 2002 02:07 am, Francois Gouget wrote:
Does this work?
It seems to work very well! It can go to Alexandre as far as I'm concerned.
Thanks.