Win32: MinGW GCC compatibility.

Several warnings silenced, notably (ngx_socket_t) -1 is now checked
on socket operations instead of -1, as ngx_socket_t is unsigned on win32
and gcc complains on comparison.

With this patch, it's now possible to compile nginx using mingw gcc,
with options we normally compile on win32.
This commit is contained in:
Maxim Dounin 2013-09-04 20:48:28 +04:00
parent c3113c2b30
commit 98f40476ad
19 changed files with 83 additions and 33 deletions

View File

@ -33,6 +33,10 @@ if [ $OPENSSL != NONE ]; then
CORE_LIBS="$CORE_LIBS $OPENSSL/.openssl/lib/libssl.a"
CORE_LIBS="$CORE_LIBS $OPENSSL/.openssl/lib/libcrypto.a"
CORE_LIBS="$CORE_LIBS $NGX_LIBDL"
if [ "$NGX_PLATFORM" = win32 ]; then
CORE_LIBS="$CORE_LIBS -lgdi32 -lcrypt32 -lws2_32"
fi
;;
esac

View File

@ -73,6 +73,11 @@ if [ $PCRE != NONE ]; then
*)
have=NGX_PCRE . auto/have
if [ "$NGX_PLATFORM" = win32 ]; then
have=PCRE_STATIC . auto/have
fi
CORE_DEPS="$CORE_DEPS $PCRE/pcre.h"
LINK_DEPS="$LINK_DEPS $PCRE/.libs/libpcre.a"
CORE_LIBS="$CORE_LIBS $PCRE/.libs/libpcre.a"

View File

@ -23,14 +23,16 @@ case "$NGX_CC_NAME" in
ngx_pcre=`echo \-DPCRE=\"$PCRE\" | sed -e "s/\//$ngx_regex_dirsep/g"`
;;
*)
ngx_makefile=
;;
esac
case "$NGX_PLATFORM" in
if [ -n "$ngx_makefile" ]; then
win32)
cat << END >> $NGX_MAKEFILE
cat << END >> $NGX_MAKEFILE
`echo "$PCRE/pcre.lib: $PCRE/pcre.h $NGX_MAKEFILE" \
| sed -e "s/\//$ngx_regex_dirsep/g"`
@ -41,10 +43,9 @@ case "$NGX_PLATFORM" in
END
;;
else
*)
cat << END >> $NGX_MAKEFILE
cat << END >> $NGX_MAKEFILE
$PCRE/pcre.h: $PCRE/Makefile
@ -60,6 +61,4 @@ $PCRE/.libs/libpcre.a: $PCRE/Makefile
END
;;
esac
fi

View File

@ -24,6 +24,10 @@ case "$NGX_CC_NAME" in
ngx_zlib=`echo \-DZLIB=\"$ZLIB\" | sed -e "s/\//$ngx_regex_dirsep/g"`
;;
*)
ngx_makefile=
;;
esac
@ -33,13 +37,30 @@ done=NO
case "$NGX_PLATFORM" in
win32)
cat << END >> $NGX_MAKEFILE
if [ -n "$ngx_makefile" ]; then
cat << END >> $NGX_MAKEFILE
`echo "$ZLIB/zlib.lib: $NGX_MAKEFILE" | sed -e "s/\//$ngx_regex_dirsep/g"`
\$(MAKE) -f auto/lib/zlib/$ngx_makefile $ngx_opt $ngx_zlib
END
else
cat << END >> $NGX_MAKEFILE
$ZLIB/libz.a: $NGX_MAKEFILE
cd $ZLIB \\
&& \$(MAKE) distclean \\
&& \$(MAKE) -f win32/Makefile.gcc \\
CFLAGS="$ZLIB_OPT" CC="\$(CC)" \\
libz.a
END
fi
done=YES
;;

View File

@ -9,10 +9,21 @@ CORE_INCS="$WIN32_INCS"
CORE_DEPS="$WIN32_DEPS"
CORE_SRCS="$WIN32_SRCS $IOCP_SRCS"
OS_CONFIG="$WIN32_CONFIG"
CORE_LIBS="$CORE_LIBS advapi32.lib ws2_32.lib"
NGX_ICONS="$NGX_WIN32_ICONS"
SELECT_SRCS=$WIN32_SELECT_SRCS
case "$NGX_CC_NAME" in
gcc)
CORE_LIBS="$CORE_LIBS -ladvapi32 -lws2_32"
;;
*)
CORE_LIBS="$CORE_LIBS advapi32.lib ws2_32.lib"
;;
esac
EVENT_MODULES="$EVENT_MODULES $IOCP_MODULE"
EVENT_FOUND=YES

View File

@ -297,7 +297,7 @@ ngx_open_listening_sockets(ngx_cycle_t *cycle)
continue;
}
if (ls[i].fd != -1) {
if (ls[i].fd != (ngx_socket_t) -1) {
continue;
}
@ -312,7 +312,7 @@ ngx_open_listening_sockets(ngx_cycle_t *cycle)
s = ngx_socket(ls[i].sockaddr->sa_family, ls[i].type, 0);
if (s == -1) {
if (s == (ngx_socket_t) -1) {
ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
ngx_socket_n " %V failed", &ls[i].addr_text);
return NGX_ERROR;
@ -863,7 +863,7 @@ ngx_close_connection(ngx_connection_t *c)
ngx_uint_t log_error, level;
ngx_socket_t fd;
if (c->fd == -1) {
if (c->fd == (ngx_socket_t) -1) {
ngx_log_error(NGX_LOG_ALERT, c->log, 0, "connection already closed");
return;
}

View File

@ -543,7 +543,7 @@ ngx_init_cycle(ngx_cycle_t *old_cycle)
}
}
if (nls[n].fd == -1) {
if (nls[n].fd == (ngx_socket_t) -1) {
nls[n].open = 1;
}
}
@ -649,7 +649,7 @@ old_shm_zone_done:
ls = old_cycle->listening.elts;
for (i = 0; i < old_cycle->listening.nelts; i++) {
if (ls[i].remain || ls[i].fd == -1) {
if (ls[i].remain || ls[i].fd == (ngx_socket_t) -1) {
continue;
}
@ -813,7 +813,7 @@ failed:
ls = cycle->listening.elts;
for (i = 0; i < cycle->listening.nelts; i++) {
if (ls[i].fd == -1 || !ls[i].open) {
if (ls[i].fd == (ngx_socket_t) -1 || !ls[i].open) {
continue;
}

View File

@ -2221,7 +2221,7 @@ ngx_udp_connect(ngx_udp_connection_t *uc)
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, &uc->log, 0, "UDP socket %d", s);
if (s == -1) {
if (s == (ngx_socket_t) -1) {
ngx_log_error(NGX_LOG_ALERT, &uc->log, ngx_socket_errno,
ngx_socket_n " failed");
return NGX_ERROR;

View File

@ -170,7 +170,7 @@ ngx_iocp_timer(void *data)
#endif
}
#ifdef __WATCOMC__
#if defined(__WATCOMC__) || defined(__GNUC__)
return 0;
#endif
}

View File

@ -148,8 +148,8 @@ ngx_select_add_event(ngx_event_t *ev, ngx_int_t event, ngx_uint_t flags)
return NGX_ERROR;
}
if ((event == NGX_READ_EVENT) && (max_read >= FD_SETSIZE)
|| (event == NGX_WRITE_EVENT) && (max_write >= FD_SETSIZE))
if ((event == NGX_READ_EVENT && max_read >= FD_SETSIZE)
|| (event == NGX_WRITE_EVENT && max_write >= FD_SETSIZE))
{
ngx_log_error(NGX_LOG_ERR, ev->log, 0,
"maximum number of descriptors "

View File

@ -70,7 +70,7 @@ ngx_event_accept(ngx_event_t *ev)
s = accept(lc->fd, (struct sockaddr *) sa, &socklen);
#endif
if (s == -1) {
if (s == (ngx_socket_t) -1) {
err = ngx_socket_errno;
if (err == NGX_EAGAIN) {

View File

@ -108,7 +108,7 @@ ngx_event_post_acceptex(ngx_listening_t *ls, ngx_uint_t n)
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, &ls->log, 0,
ngx_socket_n " s:%d", s);
if (s == -1) {
if (s == (ngx_socket_t) -1) {
ngx_log_error(NGX_LOG_ALERT, &ls->log, ngx_socket_errno,
ngx_socket_n " failed");

View File

@ -31,7 +31,7 @@ ngx_event_connect_peer(ngx_peer_connection_t *pc)
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, pc->log, 0, "socket %d", s);
if (s == -1) {
if (s == (ngx_socket_t) -1) {
ngx_log_error(NGX_LOG_ALERT, pc->log, ngx_socket_errno,
ngx_socket_n " failed");
return NGX_ERROR;

View File

@ -57,7 +57,7 @@ ngx_event_pipe(ngx_event_pipe_t *p, ngx_int_t do_write)
do_write = 1;
}
if (p->upstream->fd != -1) {
if (p->upstream->fd != (ngx_socket_t) -1) {
rev = p->upstream->read;
flags = (rev->eof || rev->error) ? NGX_CLOSE_EVENT : 0;
@ -74,7 +74,9 @@ ngx_event_pipe(ngx_event_pipe_t *p, ngx_int_t do_write)
}
}
if (p->downstream->fd != -1 && p->downstream->data == p->output_ctx) {
if (p->downstream->fd != (ngx_socket_t) -1
&& p->downstream->data == p->output_ctx)
{
wev = p->downstream->write;
if (ngx_handle_write_event(wev, p->send_lowat) != NGX_OK) {
return NGX_ABORT;

View File

@ -21,7 +21,8 @@ typedef volatile ngx_atomic_uint_t ngx_atomic_t;
#define NGX_ATOMIC_T_LEN (sizeof("-2147483648") - 1)
#if defined( __WATCOMC__ ) || defined( __BORLANDC__ ) || ( _MSC_VER >= 1300 )
#if defined( __WATCOMC__ ) || defined( __BORLANDC__ ) || defined(__GNUC__) \
|| ( _MSC_VER >= 1300 )
/* the new SDK headers */

View File

@ -815,7 +815,7 @@ ngx_worker_thread(void *data)
/* THREAD: lock */
if (c[i].fd != -1 && c[i].idle) {
if (c[i].fd != (ngx_socket_t) -1 && c[i].idle) {
c[i].close = 1;
c[i].read->handler(c[i].read);
}
@ -874,7 +874,7 @@ ngx_worker_process_exit(ngx_cycle_t *cycle)
if (ngx_exiting) {
c = cycle->connections;
for (i = 0; i < cycle->connection_n; i++) {
if (c[i].fd != -1
if (c[i].fd != (ngx_socket_t) -1
&& c[i].read
&& !c[i].read->accept
&& !c[i].read->channel

View File

@ -9,6 +9,7 @@
#define _NGX_WIN32_CONFIG_H_INCLUDED_
#undef WIN32
#define WIN32 0x0400
#define _WIN32_WINNT 0x0501
@ -35,6 +36,12 @@
#include <mswsock.h>
#include <shellapi.h>
#include <stddef.h> /* offsetof() */
#ifdef __GNUC__
/* GCC MinGW's stdio.h includes sys/types.h */
#define _OFF_T_
#endif
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>

View File

@ -141,7 +141,7 @@ ngx_os_init(ngx_log_t *log)
*/
s = ngx_socket(AF_INET, SOCK_STREAM, IPPROTO_IP);
if (s == -1) {
if (s == (ngx_socket_t) -1) {
ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
ngx_socket_n " falied");
return NGX_ERROR;

View File

@ -17,7 +17,7 @@ ngx_wsarecv(ngx_connection_t *c, u_char *buf, size_t size)
u_long bytes, flags;
WSABUF wsabuf[1];
ngx_err_t err;
ngx_uint_t n;
ngx_int_t n;
ngx_event_t *rev;
wsabuf[0].buf = (char *) buf;
@ -70,7 +70,7 @@ ngx_overlapped_wsarecv(ngx_connection_t *c, u_char *buf, size_t size)
u_long bytes, flags;
WSABUF wsabuf[1];
ngx_err_t err;
ngx_uint_t n;
ngx_int_t n;
ngx_event_t *rev;
LPWSAOVERLAPPED ovlp;