bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] socklen: do not depend on sys_socket


From: Paul Eggert
Subject: Re: [PATCH] socklen: do not depend on sys_socket
Date: Sat, 19 Mar 2011 14:58:18 -0700
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.14) Gecko/20110223 Thunderbird/3.1.8

Thanks for looking into this, Bruno.  I altered the patch to reflect
your comments, with the following further ideas:

On 03/19/2011 06:49 AM, Bruno Haible wrote:
>    the 'Include' statement of the socklen module should be changed ... to
> 
>      #include <sys/types.h>
>      #if HAVE_SYS_SOCKET_H
>      #include <sys/socket.h>
>      #endif

Given the changes you proposed in the other part of your comment,
I expect it should be changed to the following instead.  That reflects
what the revised test does.

   #include <sys/types.h>
   #if HAVE_SYS_SOCKET_H
   # include <sys/socket.h>
   #elif HAVE_WS2TCPIP_H
   # include <ws2tcpip.h>
   #endif

> Also a test that defines HAVE_SYS_SOCKET_H needs to be added, then.

That shouldn't be needed, since the test is already present in the
proposed patch: gl_TYPE_SOCKLEN_T requires gl_PREREQ_TYPE_SOCKLEN_T,
which invokes AC_CHECK_HEADERS_ONCE([sys/socket.h]), which arranges to
#define HAVE_SYS_SOCKET_H.

Here's the revised proposed patch.


diff --git a/ChangeLog b/ChangeLog
index 1b42d3c..15ec20b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,21 @@
+2011-03-19  Paul Eggert  <address@hidden>
+
+       socklen: do not depend on sys_socket
+       While trying to modify Emacs to use gnulib's socklen module,
+       I discovered a circular dependency: socklen depends on sys_socket
+       and vice versa.  Emacs can use socklen, but it does not need
+       sys_socket because it has its own substitute for sys/socket.h.
+       This patch incorporates improvements suggested by Bruno Haible
+       <http://lists.gnu.org/archive/html/bug-gnulib/2011-03/msg00211.html>.
+       * m4/socklen.m4 (gl_PREREQ_TYPE_SOCKLEN_T): New macro, taken from
+       parts of gl_PREREQ_SYS_H_SOCKET.
+       (gl_TYPE_SOCKLEN_T): Require it instead of requiring
+       gl_PREREQ_SYS_H_SOCKET.
+       * m4/sys_socket_h.m4 (gl_PREREQ_SYS_H_SOCKET): Require
+       gl_PREREQ_TYPE_SOCKLEN_T instead of doing its work ourselves.
+       * modules/socklen (Depends-on): Do not depend on sys_socket.
+       (Include): Adjust to match the test used in gl_PREREQ_TYPE_SOCKLEN_T.
+
 2011-03-19  Jim Meyering  <address@hidden>
 
        maint.mk: fix po-file syntax-check rule
diff --git a/m4/socklen.m4 b/m4/socklen.m4
index 95d4804..be012f5 100644
--- a/m4/socklen.m4
+++ b/m4/socklen.m4
@@ -1,4 +1,4 @@
-# socklen.m4 serial 9
+# socklen.m4 serial 10
 dnl Copyright (C) 2005-2007, 2009-2011 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -13,11 +13,10 @@ dnl HP-UX 10.20, IRIX 6.5, OSF/1 4.0, Interix 3.5, BeOS.
 dnl So we have to test to find something that will work.
 
 dnl On mingw32, socklen_t is in ws2tcpip.h ('int'), so we try to find
-dnl it there first.  That file is included by gnulib's sys_socket.in.h, which
-dnl all users of this module should include.  Cygwin must not include
-dnl ws2tcpip.h.
+dnl it there too.  Users of this module should use the same include
+dnl pattern that this test does.
 AC_DEFUN([gl_TYPE_SOCKLEN_T],
-  [AC_REQUIRE([gl_HEADER_SYS_SOCKET])dnl
+  [AC_REQUIRE([gl_PREREQ_TYPE_SOCKLEN_T])dnl
    AC_CHECK_TYPE([socklen_t], ,
      [AC_MSG_CHECKING([for socklen_t equivalent])
       AC_CACHE_VAL([gl_cv_socklen_t_equiv],
@@ -51,3 +50,13 @@ AC_DEFUN([gl_TYPE_SOCKLEN_T],
       #elif HAVE_WS2TCPIP_H
       # include <ws2tcpip.h>
       #endif])])
+
+AC_DEFUN([gl_PREREQ_TYPE_SOCKLEN_T],
+  [AC_CHECK_HEADERS_ONCE([sys/socket.h])
+   if test $ac_cv_header_sys_socket_h = no; then
+     dnl We cannot use AC_CHECK_HEADERS_ONCE here, because that would make
+     dnl the check for those headers unconditional; yet cygwin reports
+     dnl that the headers are present but cannot be compiled (since on
+     dnl cygwin, all socket information should come from sys/socket.h).
+     AC_CHECK_HEADERS([ws2tcpip.h])
+   fi])
diff --git a/m4/sys_socket_h.m4 b/m4/sys_socket_h.m4
index 12dc05d..0ba6109 100644
--- a/m4/sys_socket_h.m4
+++ b/m4/sys_socket_h.m4
@@ -1,4 +1,4 @@
-# sys_socket_h.m4 serial 21
+# sys_socket_h.m4 serial 22
 dnl Copyright (C) 2005-2011 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -101,17 +101,12 @@ AC_DEFUN([gl_HEADER_SYS_SOCKET],
 AC_DEFUN([gl_PREREQ_SYS_H_SOCKET],
 [
   dnl Check prerequisites of the <sys/socket.h> replacement.
-  gl_CHECK_NEXT_HEADERS([sys/socket.h])
+  AC_REQUIRE([gl_PREREQ_TYPE_SOCKLEN_T])
   if test $ac_cv_header_sys_socket_h = yes; then
     HAVE_SYS_SOCKET_H=1
     HAVE_WS2TCPIP_H=0
   else
     HAVE_SYS_SOCKET_H=0
-    dnl We cannot use AC_CHECK_HEADERS_ONCE here, because that would make
-    dnl the check for those headers unconditional; yet cygwin reports
-    dnl that the headers are present but cannot be compiled (since on
-    dnl cygwin, all socket information should come from sys/socket.h).
-    AC_CHECK_HEADERS([ws2tcpip.h])
     if test $ac_cv_header_ws2tcpip_h = yes; then
       HAVE_WS2TCPIP_H=1
     else
diff --git a/modules/socklen b/modules/socklen
index 4986f10..556336b 100644
--- a/modules/socklen
+++ b/modules/socklen
@@ -5,7 +5,6 @@ Files:
 m4/socklen.m4
 
 Depends-on:
-sys_socket
 
 configure.ac:
 gl_TYPE_SOCKLEN_T
@@ -13,8 +12,12 @@ gl_TYPE_SOCKLEN_T
 Makefile.am:
 
 Include:
-<sys/types.h>
-<sys/socket.h>
+#include <sys/types.h>
+#if HAVE_SYS_SOCKET_H
+# include <sys/socket.h>
+#elif HAVE_WS2TCPIP_H
+# include <ws2tcpip.h>
+#endif
 
 License:
 unlimited




reply via email to

[Prev in Thread] Current Thread [Next in Thread]