Re: gnulib-tool --avoid problems

2009-08-02 Thread Bruno Haible
Hi Sam,

Sam Steingold wrote:
> I am trying to use the gnulib-tool --avoid to put the gnulib regexp code
> in the regexp directory, fnmatch code in the wildcard dir &c.
> So far I came up with the following in Makefile.devel:
> 
> GNULIB = $(GNULIB_CHECKOUT)/gnulib-tool --import --no-vc-files --no-libtool \
>   --no-changelog --aux-dir=src/build-aux
> GNULIB_CORE = stdint stdbool havelib gettext localcharset \
>   uniwidth/width streq uniname/uniname unitypes link-follow \
>   nocrash libsigsegv gnu-make gettimeofday getpagesize sys_time
> # these modules are included as dependencies by regexp and fnmatch
> # so we include them here so that they appear once in src/gl*
> # instead of twice in regexp/gl* and wildcard/gl*
> GNULIB_MODULES = alloca-opt alloca extensions include_next verify \
>   mbsinit wchar wctype mbrtowc mbsrtowcs \
>   memmove memcmp memchr
> GNULIB_COMMON = $(GNULIB_CORE) $(GNULIB_MODULES)
> GNULIB_AVOID = $(addprefix --avoid=, $(GNULIB_COMMON))
> gnulib-imported : update-gnulib force
>   $(RM) configure.ac; ln -sv src/configure.in configure.ac
>   $(GNULIB) --source-base=src/gllib --m4-base=src/glm4 $(GNULIB_COMMON)
>   $(GNULIB) --source-base=modules/regexp/gllib --macro-prefix=rx_gl \
>   --m4-base=modules/regexp/glm4 $(GNULIB_AVOID) regex
>   $(GNULIB) --source-base=modules/wildcard/gllib --macro-prefix=wc_gl \
>   --m4-base=modules/wildcard/glm4 $(GNULIB_AVOID) fnmatch-gnu
>   $(RM) configure.ac
>   for d in src/gllib modules/regexp/gllib modules/wildcard/gllib; do \
> $(RM) `find $d -name \*~`; done

Looks all reasonable.

> alas, there is still some duplication between
> modules/regexp/glm4 and src/glm4, specifically:
>   codeset.m4
>   locale-fr.m4
>   locale-ja.m4
>   locale-zh.m4
>   mbrtowc.m4
>   mbstate_t.m4
>   unistd_h.m4

Duplication between .m4 files is harmless. The files are identical, therefore
'aclocal' cannot pick the "wrong" one.

> and between modules/regexp/gllib and src/gllib, specifically:
>   unistd.in.h

You should be able to fix this by adding 'unistd' to your GNULIB_CORE variable.

> also, build-dir/gllib no longer builds:
> 
> $ make gllib
> mkdir -p gllib
> if test ! -f gllib/Makefile; then sh config.status gllib/Makefile depfiles; fi
> config.status: creating gllib/Makefile
> config.status: executing depfiles commands
> cd gllib && make CFLAGS="-W -Wswitch -Wcomment -Wpointer-arith -Wimplicit 
> -Wreturn-type -Wmissing-declarations -Wno-sign-compare -Wno-format-nonliteral 
> -O2 -fexpensive-optimizations -falign-functions=4 -DUNICODE -DDYNAMIC_FFI -I. 
> "
> make[1]: Entering directory `/home/sds/src/clisp/current/build-O/gllib'
> ...
> rm -f string.h-t string.h
> { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \
> sed -e 's|@''INCLUDE_NEXT''@|include_next|g' \
> -e 's|@''PRAGMA_SYSTEM_HEADER''@|#pragma GCC system_header|g' \
> -e 's|@''NEXT_STRING_H''@||g' \
> -e 's|@''GNULIB_MBSLEN''@||g' \
> -e 's|@''GNULIB_MBSNLEN''@||g' \
> ...
> ./string.h:27:15: error: #include_next expects "FILENAME" or 
> ./string.h:54:5: error: #if with no expression

The 'string' module occurs as dependency of the 'memchr' module or 'mbsrtowcs'
modules. Somehow a bunch of AC_SUBSTed variables (such as NEXT_STRING_H)
are not correctly substituted. You should verify that
  1) gllib/Makefile.in contains the line
   NEXT_STRING_H = @NEXT_STRING_H@
  2) config.status contains the line
   S["NEXT_STRING_H"]=""
  3) configure contains the lines
   NEXT_STRING_H
 and
NEXT_STRING_H=$gl_cv_next_string_h

If 1) is not fulfilled, you should look at the automake invocation that
you issued after the autoconf invocation after the gnulib-tool invocations.

If 3) is not fulfilled, it's time to look at your autoconf and m4 versions.

If 2) is not fulfilled but 3) is, what are your versions of sh (bash?) and
awk (gawk)?

Bruno




Re: gethostname on Windows

2009-08-02 Thread Bruno Haible
Simon Josefsson wrote:
> > I'm undecided.
> 
> Avoiding -lws2_32 is good, but if the application links to -lws2_32
> anyway, there will be no saving.
> ...
> Some additional questions:
> 
> 1) How do I use it?  This doesn't seem to work:
> 
> j...@mocca:~$ cat foo.c
> #define WINVER 0x0500
> #include 
> #include 
> int main () {
>   char out[1024];
>   DWORD size = 1024;
>   BOOL t = GetComputerNameEx(ComputerNameDnsHostname, out, &size);
>   printf("hi %d: %s", t, out);
> }
> j...@mocca:~$ i586-mingw32msvc-gcc -o foo.exe foo.c 
> /tmp/ccDXn2yi.o:foo.c:(.text+0x37): undefined reference to 
> `_GetComputerNameEx'
> collect2: ld returned 1 exit status
> j...@mocca:~$ 
>
> 2) What is the maximum string size that GetComputerNameEx can return?
>For the gethostname, the max size is documented.
> 
> 3) Is the GetComputerNameEx semantics right?

You are right. In summary:

   - GetComputerNameEx(ComputerNameDnsHostname,...) returns the right hostname,
 but it hard to use portably:
   - It requires defining _WIN32_WINNT to at least 0x0500.
   - With mingw, it also requires
 "#define GetComputerNameEx GetComputerNameExA".
   - With older versions of mingw, none of the declarations are present at
 all, not even of the enum value ComputerNameDnsHostname.
   - GetComputerName() does not return the right kind of hostname.
   - gethostname() requires linking with -lws2_32.

I'm now convinced that linking with -lws2_32 is the least evil.
I have applied your patch from 2009-03-31.

Also, I'm fixing the handling of len > INT_MAX.


2009-08-02  Bruno Haible  

* lib/gethostname.c (gethostname): Fix handling of large len argument.
Add comments.

--- lib/gethostname.c.orig  2009-08-02 12:02:00.0 +0200
+++ lib/gethostname.c   2009-08-02 11:59:12.0 +0200
@@ -21,6 +21,7 @@
 #include 
 
 #if !((defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__)
+/* Unix API.  */
 
 /* Specification.  */
 #include 
@@ -59,6 +60,17 @@
 }
 
 #else
+/* Native Windows API.  Which primitive to choose?
+   - gethostname() requires linking with -lws2_32.
+   - GetComputerName() does not return the right kind of hostname.
+   - GetComputerNameEx(ComputerNameDnsHostname,...) returns the right hostname,
+ but it hard to use portably:
+   - It requires defining _WIN32_WINNT to at least 0x0500.
+   - With mingw, it also requires
+ "#define GetComputerNameEx GetComputerNameExA".
+   - With older versions of mingw, none of the declarations are present at
+ all, not even of the enum value ComputerNameDnsHostname.
+   So we use gethostname().  Linking with -lws2_32 is the least evil.  */
 
 #define WIN32_LEAN_AND_MEAN
 /* Get winsock2.h. */
@@ -70,9 +82,13 @@
 #undef gethostname
 
 int
-rpl_gethostname (char *name, size_t namelen)
+rpl_gethostname (char *name, size_t len)
 {
-  int r = gethostname (name, (int) namelen);
+  int r;
+
+  if (len > INT_MAX)
+len = INT_MAX;
+  r = gethostname (name, (int) len);
   if (r < 0)
 set_winsock_errno ();
 




Re: [PATCH] top/maint.mk: improved regex parser used in update-NEWS-hash

2009-08-02 Thread Peter Simons
Hi Jim,

 > Pushed with adjusted log message, i.e, to start with the
 > "module-name: " and to use ChangeLog-style "* dir/file (): ..."
 > description.

thank you for editing my patch to conform to the guidelines. 
Next time, I'll put more effort into getting that right.

Take care,
Peter




Re: HOST_NAME_MAX

2009-08-02 Thread Bruno Haible
Simon Josefsson wrote on 2009-04-01:
> > The definition can be triggered by the 'gethostname' module. I don't think
> > anyone will need HOST_NAME_MAX without needing the gethostname() function.
> 
> That would be fine with me.  How about the patch below?  This is on top
> of my earlier gethostname patch for mingw.
> 
> /Simon
> 
> diff --git a/doc/posix-headers/limits.texi b/doc/posix-headers/limits.texi
> index 0b5e431..d404b9c 100644
> --- a/doc/posix-headers/limits.texi
> +++ b/doc/posix-headers/limits.texi
> @@ -11,4 +11,7 @@ Portability problems fixed by Gnulib:
>  
>  Portability problems not fixed by Gnulib:
>  @itemize
> +The @code{HOST_NAME_MAX} symbol is not defined under Windows, use the
> +...@code{gethostname} gnulib module to get it.
> +
>  @end itemize
> diff --git a/m4/gethostname.m4 b/m4/gethostname.m4
> index 620e023..a2b8e60 100644
> --- a/m4/gethostname.m4
> +++ b/m4/gethostname.m4
> @@ -42,7 +42,13 @@ AC_DEFUN([gl_FUNC_GETHOSTNAME],
>  
>  # Prerequisites of lib/gethostname.c.
>  AC_DEFUN([gl_PREREQ_GETHOSTNAME], [
> -  if test "$gl_cv_w32_gethostname" != "yes"; then
> +  if test "$gl_cv_w32_gethostname" = "yes"; then
> +#  says:
> +# "if a buffer of 256 bytes is passed in the name parameter and
> +# the namelen parameter is set to 256, the buffer size will always
> +# be adequate."
> +AC_DEFINE([HOST_NAME_MAX], [256], [Define HOST_NAME_MAX on Mingw.])
> +  else
>  AC_CHECK_FUNCS([uname])
>fi
>  ])
> diff --git a/modules/gethostname b/modules/gethostname
> index e21afe6..a50c22b 100644
> --- a/modules/gethostname
> +++ b/modules/gethostname
> @@ -1,5 +1,5 @@
>  Description:
> -gethostname() function: Return machine's hostname.
> +Provide HOST_NAME_MAX and gethostname() function: Return machine's hostname.
>  
>  Files:
>  lib/gethostname.c
> diff --git a/tests/test-gethostname.c b/tests/test-gethostname.c
> index ef50953..c1914fd 100644
> --- a/tests/test-gethostname.c
> +++ b/tests/test-gethostname.c
> @@ -1,5 +1,5 @@
>  /*
> - * Copyright (C) 2008 Free Software Foundation
> + * Copyright (C) 2008, 2009 Free Software Foundation
>   * Written by Simon Josefsson.
>   *
>   * This program is free software: you can redistribute it and/or modify
> @@ -28,9 +28,15 @@
>  int
>  main (int argc, char *argv[])
>  {
> -  char buf[2500];
> +  char buf[HOST_NAME_MAX];
>int rc;
>  
> +  if (strlen (NOHOSTNAME) >= HOST_NAME_MAX)
> +{
> +  printf ("HOST_NAME_MAX impossibly small?! %d\n", HOST_NAME_MAX);
> +  return 2;
> +}
> +
>strcpy (buf, NOHOSTNAME);
>  
>rc = gethostname (buf, sizeof (buf));
> 
> 

I've applied it with a few tweaks, as follows:
  - Document the problem under "problems fixed by Gnulib", not under
"problems not fixed by Gnulib".
  - Move the AC_DEFINE out of gl_PREREQ_GETHOSTNAME, since it's the
user who wants HOST_NAME_MAX; the code in lib/gethostname.c does
not need it.


2009-08-02  Simon Josefsson  
Bruno Haible  

Ensure HOST_NAME_MAX as part of the gethostname module.
* m4/gethostname.m4 (gl_FUNC_GETHOSTNAME): On native Windows platforms,
define also HOST_NAME_MAX.
* tests/test-gethostname.c (main): Check also HOST_NAME_MAX.
* doc/posix-headers/limits.texi: Document the mingw problem.

--- doc/posix-headers/limits.texi.orig  2009-08-02 12:23:35.0 +0200
+++ doc/posix-headers/limits.texi   2009-08-02 12:19:39.0 +0200
@@ -3,10 +3,12 @@
 
 POSIX specification: @url{http://www.opengroup.org/susv3xbd/limits.h.html}
 
-Gnulib module: ---
+Gnulib module: gethostname
 
 Portability problems fixed by Gnulib:
 @itemize
+The @code{HOST_NAME_MAX} macro is not defined on some platforms:
+mingw.
 @end itemize
 
 Portability problems not fixed by Gnulib:
--- m4/gethostname.m4.orig  2009-08-02 12:23:35.0 +0200
+++ m4/gethostname.m4   2009-08-02 12:23:30.0 +0200
@@ -1,9 +1,12 @@
-# gethostname.m4 serial 6
+# gethostname.m4 serial 7
 dnl Copyright (C) 2002, 2008, 2009 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
 dnl with or without modifications, as long as this notice is preserved.
 
+# Ensure
+# - the gethostname() function,
+# - the HOST_NAME_MAX macro in .
 AC_DEFUN([gl_FUNC_GETHOSTNAME],
 [
   AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
@@ -38,6 +41,16 @@
 HAVE_GETHOSTNAME=0
 gl_PREREQ_GETHOSTNAME
   fi
+
+  dnl Also provide HOST_NAME_MAX when  lacks it.
+  if test "$gl_cv_w32_gethostname" = "yes"; then
+#  says:
+# "if a buffer of 256 bytes is passed in the name parameter and
+# the namelen parameter is set to 256, the buffer size will always
+# be adequate."
+AC_DEFINE([HOST_NAME_MAX], [256],
+  [Define HOST_NAME_MAX when  does not define it.])
+  fi
 ])
 
 # Prerequisites of lib/gethostnam

Re: HOST_NAME_MAX

2009-08-02 Thread Bruno Haible
> 2009-08-02  Simon Josefsson  
> Bruno Haible  
> 
>   Ensure HOST_NAME_MAX as part of the gethostname module.
>   * m4/gethostname.m4 (gl_FUNC_GETHOSTNAME): On native Windows platforms,
>   define also HOST_NAME_MAX.
>   * tests/test-gethostname.c (main): Check also HOST_NAME_MAX.
>   * doc/posix-headers/limits.texi: Document the mingw problem.

Well, that led to a compilation error on Linux:

test-gethostname.c: In function ‘main’:
test-gethostname.c:31: error: ‘HOST_NAME_MAX’ undeclared (first use in this 
function)
test-gethostname.c:31: error: (Each undeclared identifier is reported only once
test-gethostname.c:31: error: for each function it appears in.)

Fixed as follows:

*** tests/test-gethostname.c.orig   2009-08-02 15:28:53.0 +0200
--- tests/test-gethostname.c2009-08-02 15:26:10.0 +0200
***
*** 17,23 
--- 17,26 
  
  #include 
  
+ /* Get gethostname() declaration.  */
  #include 
+ /* Get HOST_NAME_MAX definition.  */
+ #include 
  
  #include 
  #include 




gethostname, socket need startup code

2009-08-02 Thread Bruno Haible
Hi Simon,

On mingw, the gethostname test fails for me:

  gethostname failed, rc -1 errno 10093
  FAIL: test-gethostname.exe

The reason is that the WSAStartup function has not been called. Why not make
this initialization implicitly in the gethostname function? And likewise for
the socket() function? With that, the unit tests (test-select.c and test-poll.c)
don't need to do this initialization explicitly any more. One less portability
problem when porting to mingw.

Here are two proposed patches. I verified that the behaviour of test-select
and test-poll does not change, and it fixes the gethostname failure.


2009-08-02  Bruno Haible  

Allow multiple calls to gl_sockets_startup.
* lib/sockets.c (initialized_sockets_version): New variable.
(gl_sockets_startup): Do nothing if already called for this or a higher
version.
(gl_sockets_cleanup): Reset initialized_sockets_version.

*** lib/sockets.c.orig  2009-08-02 16:35:41.0 +0200
--- lib/sockets.c   2009-08-02 16:31:19.0 +0200
***
*** 69,91 
  
  static struct close_hook close_sockets_hook;
  
  #endif
  
  int
  gl_sockets_startup (int version)
  {
  #if WINDOWS_SOCKETS
!   WSADATA data;
!   int err;
  
!   err = WSAStartup (version, &data);
!   if (err != 0)
! return 1;
  
!   if (data.wVersion < version)
! return 2;
  
!   register_close_hook (close_fd_maybe_socket, &close_sockets_hook);
  #endif
  
return 0;
--- 69,99 
  
  static struct close_hook close_sockets_hook;
  
+ static int initialized_sockets_version /* = 0 */;
+ 
  #endif
  
  int
  gl_sockets_startup (int version)
  {
  #if WINDOWS_SOCKETS
!   if (version > initialized_sockets_version)
! {
!   WSADATA data;
!   int err;
! 
!   err = WSAStartup (version, &data);
!   if (err != 0)
!   return 1;
  
!   if (data.wVersion < version)
!   return 2;
  
!   if (initialized_sockets_version == 0)
!   register_close_hook (close_fd_maybe_socket, &close_sockets_hook);
  
!   initialized_sockets_version = version;
! }
  #endif
  
return 0;
***
*** 97,102 
--- 105,112 
  #if WINDOWS_SOCKETS
int err;
  
+   initialized_sockets_version = 0;
+ 
unregister_close_hook (&close_sockets_hook);
  
err = WSACleanup ();


2009-08-02  Bruno Haible  

Implicitly initialize the sockets library.
* lib/gethostname.c: Include sockets.h.
(rpl_gethostname): Invoke gl_sockets_startup.
* lib/socket.c: Include sockets.h.
(rpl_socket): Invoke gl_sockets_startup.
* modules/gethostname (Depends-on): Add sockets.
* modules/socket (Depends-on): Likewise.
* tests/test-poll.c: Don't include sockets.h.
(main): Don't invoke gl_sockets_startup.
* tests/test-select.c: Don't include sockets.h.
(main): Don't invoke gl_sockets_startup.

--- lib/gethostname.c.orig  2009-08-02 16:43:05.0 +0200
+++ lib/gethostname.c   2009-08-02 16:10:57.0 +0200
@@ -79,6 +79,8 @@
 /* Get set_winsock_errno. */
 #include "w32sock.h"
 
+#include "sockets.h"
+
 #undef gethostname
 
 int
@@ -88,6 +90,7 @@
 
   if (len > INT_MAX)
 len = INT_MAX;
+  gl_sockets_startup (SOCKETS_1_1);
   r = gethostname (name, (int) len);
   if (r < 0)
 set_winsock_errno ();
--- lib/socket.c.orig   2009-08-02 16:43:05.0 +0200
+++ lib/socket.c2009-08-02 16:23:24.0 +0200
@@ -1,6 +1,6 @@
 /* socket.c --- wrappers for Windows socket function
 
-   Copyright (C) 2008 Free Software Foundation, Inc.
+   Copyright (C) 2008-2009 Free Software Foundation, Inc.
 
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -26,12 +26,18 @@
 /* Get set_winsock_errno, FD_TO_SOCKET etc. */
 #include "w32sock.h"
 
+#include "sockets.h"
+
 int
 rpl_socket (int domain, int type, int protocol)
 {
+  SOCKET fh;
+
+  gl_sockets_startup (SOCKETS_1_1);
+
   /* We have to use WSASocket() to create non-overlapped IO sockets.
  Overlapped IO sockets cannot be used with read/write.  */
-  SOCKET fh = WSASocket (domain, type, protocol, NULL, 0, 0);
+  fh = WSASocket (domain, type, protocol, NULL, 0, 0);
 
   if (fh == INVALID_SOCKET)
 {
--- modules/gethostname.orig2009-08-02 16:43:05.0 +0200
+++ modules/gethostname 2009-08-02 16:16:26.0 +0200
@@ -10,6 +10,7 @@
 unistd
 sys_socket
 errno
+sockets
 
 configure.ac:
 gl_FUNC_GETHOSTNAME
--- modules/socket.orig 2009-08-02 16:43:05.0 +0200
+++ modules/socket  2009-08-02 16:16:35.0 +0200
@@ -8,6 +8,7 @@
 Depends-on:
 sys_socket
 errno
+sockets
 
 configure.ac:
 AC_REQUIRE([gl_HEADER_SYS_SOCKET])
--- tests/test-poll.c.orig  2009-08-02 16:43:05.0 +0200
+++ tests/test-poll.c   2009-08-02 16:13:10.0 +0200
@@ -1,5 +1,5 @@
 /* Test of poll() function.
-   Copyright (C) 2008 Free Software Foundation, Inc.
+   Cop

new modules 'uname', 'sys_utsname'

2009-08-02 Thread Bruno Haible
Now that gethostname is supported on all platforms, it's easy to add
support for the uname() function on all platforms.

Here is a proposed module 'sys_utsname', and a proposed module 'uname'
in the next mail.


2009-08-02  Bruno Haible  

New module 'sys_utsname'.
* lib/sys_utsname.in.h: New file, based on glibc's .
* m4/sys_utsname_h.m4: New file.
* modules/sys_utsname: New file.
* doc/posix-headers/sys_utsname.texi: Mention the new module.

 lib/sys_utsname.in.h 
/* Substitute for .
   Copyright (C) 2009 Free Software Foundation, Inc.

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2, or (at your option)
   any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software Foundation,
   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */

#ifndef _GL_SYS_UTSNAME_H
#define _GL_SYS_UTSNAME_H

/* The definition of GL_LINK_WARNING is copied here.  */


#ifdef __cplusplus
extern "C" {
#endif


/* Length of the entries in 'struct utsname' is 256.  */
#define _UTSNAME_LENGTH 256

#ifndef _UTSNAME_NODENAME_LENGTH
# define _UTSNAME_NODENAME_LENGTH _UTSNAME_LENGTH
#endif
#ifndef _UTSNAME_SYSNAME_LENGTH
# define _UTSNAME_SYSNAME_LENGTH _UTSNAME_LENGTH
#endif
#ifndef _UTSNAME_RELEASE_LENGTH
# define _UTSNAME_RELEASE_LENGTH _UTSNAME_LENGTH
#endif
#ifndef _UTSNAME_VERSION_LENGTH
# define _UTSNAME_VERSION_LENGTH _UTSNAME_LENGTH
#endif
#ifndef _UTSNAME_MACHINE_LENGTH
# define _UTSNAME_MACHINE_LENGTH _UTSNAME_LENGTH
#endif

/* Structure describing the system and machine.  */
struct utsname
  {
/* Name of this node on the network.  */
char nodename[_UTSNAME_NODENAME_LENGTH];

/* Name of the implementation of the operating system.  */
char sysname[_UTSNAME_SYSNAME_LENGTH];
/* Current release level of this implementation.  */
char release[_UTSNAME_RELEASE_LENGTH];
/* Current version level of this release.  */
char version[_UTSNAME_VERSION_LENGTH];

/* Name of the hardware type the system is running on.  */
char machine[_UTSNAME_MACHINE_LENGTH];
  };


#if @GNULIB_UNAME@
# if !...@have_uname@
extern int uname (struct utsname *buf);
# endif
#elif defined GNULIB_POSIXCHECK
# undef uname
# define uname(b) \
(GL_LINK_WARNING ("uname is unportable - " \
  "use gnulib module uname for portability"), \
 uname (b))
#endif


#ifdef __cplusplus
}
#endif


#endif /* _GL_SYS_UTSNAME_H */
= m4/sys_utsname_h.m4 =
# sys_utsname_h.m4 serial 1
dnl Copyright (C) 2009 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.

dnl Written by Bruno Haible.

AC_DEFUN([gl_SYS_UTSNAME_H],
[
  dnl Use AC_REQUIRE here, so that the default behavior below is expanded
  dnl once only, before all statements that occur in other macros.
  AC_REQUIRE([gl_SYS_UTSNAME_H_DEFAULTS])

  AC_CHECK_HEADERS_ONCE([sys/utsname.h])
  if test $ac_cv_header_sys_utsname_h != yes; then
SYS_UTSNAME_H='sys/utsname.h'
  fi
])

AC_DEFUN([gl_SYS_UTSNAME_MODULE_INDICATOR],
[
  dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
  AC_REQUIRE([gl_SYS_UTSNAME_H_DEFAULTS])
  
GNULIB_[]m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./-],[ABCDEFGHIJKLMNOPQRSTUVWXYZ___])=1
])

AC_DEFUN([gl_SYS_UTSNAME_H_DEFAULTS],
[
  GNULIB_UNAME=0;   AC_SUBST([GNULIB_UNAME])
  dnl Assume proper GNU behavior unless another module says otherwise.
  HAVE_UNAME=1; AC_SUBST([HAVE_UNAME])
  SYS_UTSNAME_H=''; AC_SUBST([SYS_UTSNAME_H])
])
= modules/sys_utsname =
Description:
A  for systems which lack it.

Files:
lib/sys_utsname.in.h
m4/sys_utsname_h.m4

Depends-on:
link-warning

configure.ac:
gl_SYS_UTSNAME_H
AC_PROG_MKDIR_P

Makefile.am:
BUILT_SOURCES += $(SYS_UTSNAME_H)

# We need the following in order to create  when the system
# does not have one.
sys/utsname.h: sys_utsname.in.h
@MKDIR_P@ sys
rm -f $...@-t $@
{ echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
  sed -e 's|@''GNULIB_UNAME''@|$(GNULIB_UNAME)|g' \
  -e 's|@''HAVE_UNAME''@|$(HAVE_UNAME)|g' \
  -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \
  < $(srcdir)/sys_utsname.in.h; \
} > $...@-t
mv $.

Re: gethostname, socket need startup code

2009-08-02 Thread Paolo Bonzini

On 08/02/2009 04:45 PM, Bruno Haible wrote:

Hi Simon,

On mingw, the gethostname test fails for me:

   gethostname failed, rc -1 errno 10093
   FAIL: test-gethostname.exe

The reason is that the WSAStartup function has not been called. Why not make
this initialization implicitly in the gethostname function? And likewise for
the socket() function? With that, the unit tests (test-select.c and test-poll.c)
don't need to do this initialization explicitly any more. One less portability
problem when porting to mingw.

Here are two proposed patches. I verified that the behaviour of test-select
and test-poll does not change, and it fixes the gethostname failure.


I'm wondering if some programs out there used WSAStartup autonomously 
without going through the sockets module...


Paolo




new module 'uname'

2009-08-02 Thread Bruno Haible
Here is the proposed 'uname' module. On mingw it produces values like
the following:

uname -n = nodename   = pusillus
uname -s = sysname= MINGW32_NT-5.1
uname -r = release= Windows XP
uname -v = version= Service Pack 3
uname -m = machine or cpu = i686

The nodename result is the same as gethostname().

The sysname result is chosen in a way compatible with the msys uname.exe,
so that config.guess will work fine when used with coreutils uname.exe.

The release and version fields are human-readable.

Bruno


2009-08-02  Bruno Haible  

New module 'uname'.
* lib/uname.c: New file.
* m4/uname.m4: New file.
* modules/uname: New file.
* doc/posix-functions/uname.texi: Mention the new module.

= lib/uname.c =
/* uname replacement.
   Copyright (C) 2009 Free Software Foundation, Inc.

   This program is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see .  */

#include 

/* Specification.  */
#include 

/* This file provides an implementation only for the native Windows API.  */
#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__

#include 
#include 
#include 

/* Mingw headers don't have latest processor codes.  */
#ifndef PROCESSOR_AMD_X8664
# define PROCESSOR_AMD_X8664 8664
#endif

int
uname (struct utsname *buf)
{
  OSVERSIONINFO version;
  BOOL have_version;
  const char *super_version;

  /* Fill in nodename.  */
  if (gethostname (buf->nodename, sizeof (buf->nodename)) < 0)
strcpy (buf->nodename, "localhost");

  /* Determine major-major Windows version.  */
  version.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
  have_version = GetVersionEx (&version);
  if (have_version)
{
  if (version.dwPlatformId == VER_PLATFORM_WIN32_NT)
{
  /* Windows NT or newer.  */
  super_version = "NT";
}
  else if (version.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
{
  /* Windows 95/98/ME.  */
  switch (version.dwMinorVersion)
{
case 0:
  super_version = "95";
  break;
case 10:
  super_version = "98";
  break;
case 90:
  super_version = "ME";
  break;
default:
  super_version = "";
  break;
}
}
  else
super_version = "";
}
  else
super_version = "";

  /* Fill in sysname.  */
#ifdef __MINGW32__
  /* Returns a string compatible with the MSYS uname.exe program,
 so that no further changes are needed to GNU config.guess.
 For example,
   $ ./uname.exe -s  => MINGW32_NT-5.1
   */
  if (have_version)
sprintf (buf->sysname, "MINGW32_%s-%u.%u", super_version,
 (unsigned int) version.dwMajorVersion,
 (unsigned int) version.dwMinorVersion);
  else
strcpy (buf->sysname, "MINGW32");
#else
  if (have_version)
sprintf (buf->sysname, "Windows%s", super_version);
  else
strcpy (buf->sysname, "Windows");
#endif

  /* Fill in release, version.  */
  /* The MSYS uname.exe programs uses strings from a modified Cygwin runtime:
   $ ./uname.exe -r  => 1.0.11(0.46/3/2)
   $ ./uname.exe -v  => 2008-08-25 23:40
 There is no point in imitating this behaviour.  */
  if (have_version)
{
  if (version.dwPlatformId == VER_PLATFORM_WIN32_NT)
{
  /* Windows NT or newer.  */
  if (version.dwMajorVersion <= 4)
sprintf (buf->release, "Windows NT %u.%u",
 (unsigned int) version.dwMajorVersion,
 (unsigned int) version.dwMinorVersion);
  else if (version.dwMajorVersion == 5)
switch (version.dwMinorVersion)
  {
  case 0:
strcpy (buf->release, "Windows 2000");
break;
  case 1:
strcpy (buf->release, "Windows XP");
break;
  case 2:
strcpy (buf->release, "Windows Server 2003");
break;
  default:
strcpy (buf->release, "Windows");
break;
  }
  else if (version.dwMajorVersion == 6)
{
  OSVERSIONINFOEX versionex;

  versionex.dwOSVersionInfoSize = sizeof (OSVERSIONINFOEX);
  if 

Re: gethostname, socket need startup code

2009-08-02 Thread Bruno Haible
Paolo Bonzini wrote:
> I'm wondering if some programs out there used WSAStartup autonomously 
> without going through the sockets module...

That would not hurt. WSAStartup succeeds when called repeatedly, even
when called with different version numbers:

$ cat foo.c
#include 
#include 
#include 
int main()
{
  WSADATA data;
  int err;

  err = WSAStartup (0x101, &data);
  printf ("%d\n", err);
  err = WSAStartup (0x101, &data);
  printf ("%d\n", err);
  err = WSAStartup (0x201, &data);
  printf ("%d\n", err);
  err = WSAStartup (0x101, &data);
  printf ("%d\n", err);
  return 0;
}

$ gcc -mno-cygwin foo.c -lws2_32

$ ./a.exe 
0
0
0
0


Bruno




Re: gethostname on Windows

2009-08-02 Thread Martin Lambers
On Sun, 02. Aug 2009, 12:04:53 +0200, Bruno Haible wrote:
> Simon Josefsson wrote:
> > Avoiding -lws2_32 is good, but if the application links to -lws2_32
> > anyway, there will be no saving.
> > [...]
> 
> [...]
> I'm now convinced that linking with -lws2_32 is the least evil.
> I have applied your patch from 2009-03-31.

Thanks to both of you!

> Also, I'm fixing the handling of len > INT_MAX.

This requires to include limits.h in gethostname.c, to get INT_MAX.

Martin


diff --git a/lib/gethostname.c b/lib/gethostname.c
index ef58a40..422184a 100644
--- a/lib/gethostname.c
+++ b/lib/gethostname.c
@@ -76,6 +76,9 @@ gethostname (char *name, size_t len)
 /* Get winsock2.h. */
 #include 
 
+/* Get INT_MAX. */
+#include 
+
 /* Get set_winsock_errno. */
 #include "w32sock.h"
 




Re: gethostname on Windows

2009-08-02 Thread Bruno Haible
Martin Lambers wrote:
> This requires to include limits.h in gethostname.c, to get INT_MAX.
> 
> Martin
> 
> 
> diff --git a/lib/gethostname.c b/lib/gethostname.c
> index ef58a40..422184a 100644
> --- a/lib/gethostname.c
> +++ b/lib/gethostname.c
> @@ -76,6 +76,9 @@ gethostname (char *name, size_t len)
>  /* Get winsock2.h. */
>  #include 
>  
> +/* Get INT_MAX. */
> +#include 
> +
>  /* Get set_winsock_errno. */
>  #include "w32sock.h"

Oops, you're right. Thanks. Applied.

Bruno




Re: updating copyright years

2009-08-02 Thread Simon Josefsson
"Joel E. Denny"  writes:

>> For example I note that
>>   $ build-aux/update-copyright < lib/gc-gnulib.c
>> gives a warning.
>
> That doesn't contain an FSF copyright, so an update-copyright makefile 
> target should probably just exclude it.

That was a mistake when adding the file into gnulib, now fixed.

/Simon




Re: gethostname, socket need startup code

2009-08-02 Thread Paolo Bonzini

Good.  No one asks worse than 1.1 so the patch is okay.

Paolo




Re: gnulib-tool --avoid problems

2009-08-02 Thread Sam Steingold
Hi Bruno,

On Sun, Aug 2, 2009 at 5:01 AM, Bruno Haible wrote:
> Sam Steingold wrote:
>> alas, there is still some duplication between
>> modules/regexp/glm4 and src/glm4, specifically:
>>           codeset.m4
>>           locale-fr.m4
>>           locale-ja.m4
>>           locale-zh.m4
>>           mbrtowc.m4
>>           mbstate_t.m4
>>           unistd_h.m4
>
> Duplication between .m4 files is harmless.

but _extremely_ unaesthetic.
there should be a way around.
the best way, IMO, is to enable a _shared_ glm4 between src, regexp
and wildcard.

>> and between modules/regexp/gllib and src/gllib, specifically:
>>           unistd.in.h
>
> You should be able to fix this by adding 'unistd' to your GNULIB_CORE 
> variable.

thanks, it worked.


>> also, build-dir/gllib no longer builds:
>>
>> $ make gllib
>> mkdir -p gllib
>> if test ! -f gllib/Makefile; then sh config.status gllib/Makefile depfiles; 
>> fi
>> config.status: creating gllib/Makefile
>> config.status: executing depfiles commands
>> cd gllib && make CFLAGS="-W -Wswitch -Wcomment -Wpointer-arith -Wimplicit 
>> -Wreturn-type -Wmissing-declarations -Wno-sign-compare 
>> -Wno-format-nonliteral -O2 -fexpensive-optimizations -falign-functions=4 
>> -DUNICODE -DDYNAMIC_FFI -I. "
>> make[1]: Entering directory `/home/sds/src/clisp/current/build-O/gllib'
>> ...
>> rm -f string.h-t string.h
>> { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \
>>         sed -e 's|@''INCLUDE_NEXT''@|include_next|g' \
>>             -e 's|@''PRAGMA_SYSTEM_HEADER''@|#pragma GCC system_header|g' \
>>             -e 's|@''NEXT_STRING_H''@||g' \
>>             -e 's|@''GNULIB_MBSLEN''@||g' \
>>             -e 's|@''GNULIB_MBSNLEN''@||g' \
>> ...
>> ./string.h:27:15: error: #include_next expects "FILENAME" or 
>> ./string.h:54:5: error: #if with no expression
>
> The 'string' module occurs as dependency of the 'memchr' module or 'mbsrtowcs'
> modules. Somehow a bunch of AC_SUBSTed variables (such as NEXT_STRING_H)
> are not correctly substituted. You should verify that
>  1) gllib/Makefile.in contains the line
>       NEXT_STRING_H = @NEXT_STRING_H@

nope:
$ grep NEXT_STRING_H src/gllib/Makefile.in
  -e 's|@''NEXT_STRING_H''@|$(NEXT_STRING_H)|g' \



>  2) config.status contains the line
>       S["NEXT_STRING_H"]=""

nope, does not contain NEXT_STRING_H at all.


>  3) configure contains the lines
>       NEXT_STRING_H
>     and
>            NEXT_STRING_H=$gl_cv_next_string_h

nope, no NEXT_STRING_H either.

> If 1) is not fulfilled, you should look at the automake invocation that
> you issued after the autoconf invocation after the gnulib-tool invocations.

$ make -f Makefile.devel src/gllib/Makefile.in
cd src/gllib && cd .. && automake gllib/Makefile
$

no diagnostics.

> If 3) is not fulfilled, it's time to look at your autoconf and m4 versions.

autoconf (GNU Autoconf) 2.63
m4 (GNU M4) 1.4.11

> If 2) is not fulfilled but 3) is, what are your versions of sh (bash?) and
> awk (gawk)?

GNU Awk 3.1.6
GNU bash, version 3.2.48(1)-release


-- 
Sam Steingold 




Re: [PATCH] My version of pipe-filter

2009-08-02 Thread Bruno Haible
Hi Paolo,

> here is a version of pipe-filter that works under Win32
> too (tested with Wine), has tests, and so on.
> 
> Testing under native Windows would be appreciated.
> 
> Bruno, what do you think?

I've added yours under the name 'pipe-filter-gi' and mine under the name
'pipe-filter-ii'. The 'g' stands for the "generator" and the 'i' for the
iterator argument type.

Your code and test suite prompted changes also for pipe-filter-ii:
  - argv argument is now 'const char **' instead of 'char **'.
  - Handling of write to closed pipe on Woe32: Here errno is EINVAL by
default instead of EPIPE on Unix.
  - Handle the case that create_pipe_bidi returns -1.
  - Set SIGPIPE handler to SIG_IGN while writing to the subprocess.
  - Optim: Initialize readfds and writefds once, outside the loop.

On the side of pipe-filter-gi, I made the following changes:
* Behaviour:
  - When the child closes its standard input while the parent is
still writing on it, treat it like an error, with errno = EPIPE.
Normally this situation indicates that the parent and child
don't agree on a protocol, or that the child exited prematurely.
* API:
  - Use 2 callback functions for the reader iterator, not just one.
This allows to avoid memcpy in some use cases.
  - When there was an error and the child process returns, return
the error code, not the child's exit status.
* Details:
  - Don't use assert. Use tests that are always compiled into the code.
  - In filter_terminate: Pass finish_reading = true instead of
finish_reading = false when there had been a write error but no
read error.
  - Use the same concept of return value in filter_write as in
filter_close. filter_loop no longer leaves a result in errno.
  - Handle the case that create_pipe_bidi returns -1.
  - Speed up the test suite: fewer bash 'read' calls, but use longer
strings to compensate.
* Details for the Unix implementation:
  - Set SIGPIPE handler to SIG_IGN while writing to the subprocess.
  - Don't use a 0 timeout for select(); that's a recipe for producing
CPU-burning loops. When select() returns 0, abort.
  - Correct the logic in filter_loop: Use the same if() conditions,
not 'if (!f->writer_errno)' in one place and 'if (count)' in another.
  - Also in filter_loop, when !HAVE_SELECT: A 'continue' statement
was wrong.
  - Also in filter_loop: Terminate the loop when count becomes 0.
  - Also in filter_loop: When read() returns 0, don't terminate the
loop. Instead, continue to write the given data.
* Details for the Woe32 implementation:
  - For synchronization between the two threads, use a CRITICAL_SECTION
object instead of a mutex HANDLE. It's faster. Mutexes are needed
only when synchronizing threads in different processes.
  - In reader_thread_func, don't ignore the errno from the read() call.
  - In filter_loop, use write() repeatedly, to protect against short
writes. Also protect against count > INT_MAX.

Bruno