Re: GNU sed version 4.2.1: on OS X, C locale gets aliased to UTF-8

2012-06-23 Thread Paolo Bonzini
 On the other hand, so far I saw no reply to my attempts to refute 
 counterarguments
 against these patches. So, should I just submit git patches for one (or both) 
 of them,
 for inclusion? Or does anybody still have reservations about this?

I'm waiting for feedback from the Gnulib guys.  This code comes into
sed via Gnulib.

I'd like to see this fixed soon so that I can release 4.3.

Paolo



Re: Why require SLOW_BUT_NO_HACKS for stubs?

2012-06-23 Thread Paolo Bonzini
On Sun, Jun 17, 2012 at 11:40 PM, Bruno Haible br...@clisp.org wrote:
 Isaac Dunham wrote:
  The test as it stands is error out on unsupported platforms unless
  user specifies to use slow method.
  My proposal is On unsupported platforms, use the slow method instead
  of erroring out.

 If we did this, nobody would report to bug-gnulib (or to the libc maintainer)
 the need to port the functions. You would get a slow or buggy program
 instead.

You can add a test program that detects an unported-to libc.  So they
would get a slow program but also a make check failure.

 - #error Please port gnulib freadahead.c to your platform! Look at the 
 definition of fflush, fread, ungetc on your system, then report this to 
 bug-gnulib.
 +  /* This implementation is correct on any ANSI C platform.  It is just
 +     awfully slow.  */
 +  return freading(fp)  !feof(fp);
 + #warning Please port gnulib freadahead.c to your platform! Look at the 
 definition of fflush, fread, ungetc on your system, then report this to 
 bug-gnulib.
  #endif
  }

 This alternative code is not correct. On a stream freshly opened for reading
 it returns 1 where is should return 0 instead.

Indeed, it is only correct to use this replacement in close_stdin.

Paolo



getopt_long test failure on OpenBSD 5.0

2012-06-23 Thread Bruno Haible
On OpenBSD 5.0, I'm seeing this test failure in a testdir for module
'getopt-gnu':

test-getopt_long.h:232: assertion failed
FAIL: test-getopt

The issue is with disambiguation, say, when the user enters --foo
and the available options are --foobar and --foobaz but they have the same
actions.

This fixes it by introducing a new test
checking for working GNU getopt_long function
On glibc and Cygwin 1.7:
checking for working GNU getopt_long function... yes
On OpenBSD 5.0:
checking for working GNU getopt_long function... no


2012-06-23  Bruno Haible  br...@clisp.org

getopt-gnu: Handle suboptimal getopt_long's abbreviation handling.
* m4/getopt.m4 (gl_GETOPT_CHECK_HEADERS): If getopt_long exists but
does not handle abbreviated long options with equivalent
disambiguations, set gl_replace_getopt to yes.
* doc/posix-functions/getopt.texi: Mention the OpenBSD 5.0 problem.

--- doc/posix-functions/getopt.texi.origSat Jun 23 17:04:28 2012
+++ doc/posix-functions/getopt.texi Sat Jun 23 16:20:24 2012
@@ -48,6 +48,10 @@
 The function @code{getopt_long} is missing on some platforms:
 AIX 5.1, HP-UX 11, IRIX 6.5, OSF/1 5.1, Solaris 9, MSVC 9, Interix 3.5.
 @item
+The function @code{getopt_long} does not support abbreviated long options
+where all disambiguations are equivalent on some platforms:
+OpenBSD 5.0.
+@item
 The function @code{getopt_long_only} is missing on some platforms:
 Mac OS X 10.3, FreeBSD 5.2.1, NetBSD 5.0, AIX 5.1, HP-UX 11, IRIX 6.5,
 OSF/1 5.1, Solaris 9, mingw, MSVC 9, Interix 3.5.
--- m4/getopt.m4.orig   Sat Jun 23 17:04:28 2012
+++ m4/getopt.m4Sat Jun 23 16:17:07 2012
@@ -1,4 +1,4 @@
-# getopt.m4 serial 41
+# getopt.m4 serial 42
 dnl Copyright (C) 2002-2006, 2008-2012 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -319,6 +319,48 @@
   ])
 if test $gl_cv_func_getopt_gnu = no; then
   gl_replace_getopt=yes
+else
+  AC_CACHE_CHECK([for working GNU getopt_long function],
+[gl_cv_func_getopt_long_gnu],
+[AC_RUN_IFELSE(
+   [AC_LANG_PROGRAM(
+  [[#include getopt.h
+#include stddef.h
+#include string.h
+  ]],
+  [[static const struct option long_options[] =
+  {
+{ xtremely-,no_argument,   NULL, 1003 },
+{ xtra, no_argument,   NULL, 1001 },
+{ xtreme,   no_argument,   NULL, 1002 },
+{ xtremely, no_argument,   NULL, 1003 },
+{ NULL,   0, NULL, 0 }
+  };
+/* This code fails on OpenBSD 5.0.  */
+{
+  static char program[] = program;
+  static char xtremel[] = --xtremel;
+  char *argv[] = { program, xtremel, NULL };
+  int option_index;
+  optind = 1; opterr = 0;
+  if (getopt_long (2, argv, , long_options, option_index) 
!= 1003)
+return 1;
+}
+return 0;
+  ]])],
+   [gl_cv_func_getopt_long_gnu=yes],
+   [gl_cv_func_getopt_long_gnu=no],
+   [dnl Cross compiling. Guess no on OpenBSD, yes otherwise.
+case $host_os in
+  openbsd*) gl_cv_func_getopt_long_gnu=guessing no;;
+  *)gl_cv_func_getopt_long_gnu=guessing yes;;
+esac
+   ])
+])
+  case $gl_cv_func_getopt_long_gnu in
+*yes) ;;
+*) gl_replace_getopt=yes ;;
+  esac
 fi
   fi
 ])




Re: musl compatibility

2012-06-23 Thread Paolo Bonzini
On Sun, Jun 17, 2012 at 6:15 PM, Bruno Haible br...@clisp.org wrote:
 Paul Eggert wrote:
 On 06/12/2012 04:21 AM, Paolo Bonzini wrote:
  perhaps we can follow the suggestion and
  replace if (freadahead (f)) with if (freading(f)  !feof(f)) in
  closein.c.

 Yes, thanks, I like this idea the best of those suggested so far.
 Here's a proposed patch to gnulib.

 Unfortunately, this idea will cause extra system calls for programs which
 terminate without having read from stdin.

A wrongly-nonzero freadahead is a correctness problem indeed.
However, in the case of close_stdin, is this important for something
that happens rarely, and even then at most once in a run (and
usually the time the lseek will happen anyway, because in general
stdin is read in its entirety)?

Not to mention that lseek(0, 0, SEEK_CUR) is one of the most optimized
system calls in the kernel, possibly beaten only by
gettimeofday/clock_gettime.

Paolo



Re: musl compatibility

2012-06-23 Thread Paul Eggert
On 06/23/2012 08:10 AM, Paolo Bonzini wrote:
 However, in the case of close_stdin, is this important for something
 that happens rarely

I tend to agree that it's not that important, but isn't
this question moot now that freadahead has been ported
to musl?  (And welcome back from vacation)



Re: getopt.m4 test

2012-06-23 Thread Bruno Haible
Hi Paul, Eric,

I wrote:
 It seems to me that
   - musl's getopt is POSIX compliant (at least it passes the 3 parts of
 the test when run individually).
   - The getopt.m4 test fails only because musl does not support one of
 the 3 known ways to reset option processing. Does it support another
 method, or none at all?
   - coreutils does not rely on resetting option processing with getopt(),
 only with getopt_long() (in coreutils/src/{env.c,nice.c,stty.c}).
   - The use of OPTIND_MIN in getopt.m4 exists purely to run a single
 test program rather than 3 test programs in sequence.
 
 Paul, I would suggest to split out the 3 tests into a sequence of 3 test
 programs, and then remove the determination of gl_optind_min - since
 nothing else uses it.

Here is a proposed patch to do this. Its effect is that on HP-UX, IRIX,
OSF/1, Solaris 9, and likely also musl libc the line

  checking whether getopt is POSIX compatible... no

becomes

  checking whether getopt is POSIX compatible... yes

What this change also does is to stop guaranteeing that either 'optreset'
or setting 'optind = 0;' will reset the option processing. The rationale
is that no program I've seen actually needs this: Normal programs use getopt
to loop over their arguments just once.

Also, I couldn't reproduce the described problem with mingw and leading
'+' sign (with mingw of 2009), so let's drop this from the documentation.

Here's the proposed patch. Tested to not introduce regressions in a testdir
for 'getopt-posix', nor in a testdir for 'getopt-gnu'.


2012-06-23  Bruno Haible  br...@clisp.org

getopt-posix: No longer guarantee that option processing is resettable.
* doc/posix-functions/getopt.texi: Drop description of problem with
internal state. Fix info about mingw and msvc9.
* m4/getopt.m4 (gl_GETOPT_CHECK_HEADERS): Don't require a resettable
option processing by getopt(). Run three test programs instead of one.
Simplify cross-compilation guess.
Reported by Rich Felker dal...@aerifal.cx.

--- doc/posix-functions/getopt.texi.origSat Jun 23 17:21:27 2012
+++ doc/posix-functions/getopt.texi Sat Jun 23 17:09:50 2012
@@ -13,21 +13,17 @@
 Portability problems fixed by either Gnulib module @code{getopt-posix} or 
@code{getopt-gnu}:
 @itemize
 @item
-The @code{getopt} function keeps some internal state that cannot be explicitly
-reset on some platforms:
-mingw.
+This function is missing on some platforms:
+MSVC 9.
 @item
 The value of @code{optind} after a missing required argument is wrong
 on some platforms:
-Mac OS X 10.5, AIX 7.1.
+Mac OS X 10.5, AIX 7.1, mingw.
 @end itemize
 
 Portability problems fixed by Gnulib module @code{getopt-gnu}:
 @itemize
 @item
-This function is missing on some platforms:
-MSVC 9.
-@item
 The function @code{getopt} does not support the @samp{+} flag in the options
 string on some platforms:
 Mac OS X 10.5, AIX 5.2, HP-UX 11, IRIX 6.5, OSF/1 5.1, Solaris 11 2010-11.
--- m4/getopt.m4.orig   Sat Jun 23 17:21:27 2012
+++ m4/getopt.m4Sat Jun 23 17:12:49 2012
@@ -1,4 +1,4 @@
-# getopt.m4 serial 42
+# getopt.m4 serial 43
 dnl Copyright (C) 2002-2006, 2008-2012 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -74,11 +74,6 @@
 AC_CHECK_FUNCS([getopt_long_only], [], [gl_replace_getopt=yes])
   fi
 
-  dnl mingw's getopt (in libmingwex.a) does weird things when the options
-  dnl strings starts with '+' and it's not the first call.  Some internal state
-  dnl is left over from earlier calls, and neither setting optind = 0 nor
-  dnl setting optreset = 1 get rid of this internal state.
-  dnl POSIX is silent on optind vs. optreset, so we allow either behavior.
   dnl POSIX 2008 does not specify leading '+' behavior, but see
   dnl http://austingroupbugs.net/view.php?id=191 for a recommendation on
   dnl the next version of POSIX.  For now, we only guarantee leading '+'
@@ -87,30 +82,16 @@
 AC_CACHE_CHECK([whether getopt is POSIX compatible],
   [gl_cv_func_getopt_posix],
   [
-dnl BSD getopt_long uses an incompatible method to reset option
-dnl processing.  Existence of the optreset variable, in and of
-dnl itself, is not a reason to replace getopt, but knowledge
-dnl of the variable is needed to determine how to reset and
-dnl whether a reset reparses the environment.  Solaris
-dnl supports neither optreset nor optind=0, but keeps no state
-dnl that needs a reset beyond setting optind=1; detect Solaris
-dnl by getopt_clip.
-AC_LINK_IFELSE(
-  [AC_LANG_PROGRAM(
- [[#include unistd.h]],
- [[int *p = optreset; return optreset;]])],
-  [gl_optind_min=1],
-  [AC_COMPILE_IFELSE(
- [AC_LANG_PROGRAM(
-[[#include getopt.h]],
-[[return 

Re: getopt.m4 test

2012-06-23 Thread Paul Eggert
On 06/23/2012 09:22 AM, Bruno Haible wrote:
   getopt-posix: No longer guarantee that option processing is resettable.

That looks good to me, and thanks.



Re: GNU sed version 4.2.1: on OS X, C locale gets aliased to UTF-8

2012-06-23 Thread Paul Eggert
On 06/23/2012 07:54 AM, Paolo Bonzini wrote:
 I'm waiting for feedback from the Gnulib guys.

Can you please summarize the issue, the proposed fixes,
and the pros and cons of each?  The discussion has been
spread out for so long that I've forgotten half of it.
No need for anything fancy; URLs are fine.  Thanks.



[PATCH] time: fix obsolete comment

2012-06-23 Thread Paul Eggert
 ChangeLog|6 ++
 m4/time_h.m4 |4 ++--
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 5c563fd..df89859 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2012-06-23  Paul Eggert  egg...@cs.ucla.edu
+
+   time: fix obsolete comment
+   * m4/time_h.m4 (gl_CHECK_TYPE_STRUCT_TIMESPEC): Remove obsolete
+   reference to HAVE_STRUCT_TIMESPEC in comment.
+
 2012-06-23  Bruno Haible  br...@clisp.org
 
getopt-gnu: Handle suboptimal getopt_long's abbreviation handling.
diff --git a/m4/time_h.m4 b/m4/time_h.m4
index b88da76..6415bfb 100644
--- a/m4/time_h.m4
+++ b/m4/time_h.m4
@@ -2,7 +2,7 @@
 
 # Copyright (C) 2000-2001, 2003-2007, 2009-2012 Free Software Foundation, Inc.
 
-# serial 6
+# serial 7
 
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -25,7 +25,7 @@ AC_DEFUN([gl_HEADER_TIME_H_BODY],
   AC_REQUIRE([gl_CHECK_TYPE_STRUCT_TIMESPEC])
 ])
 
-dnl Define HAVE_STRUCT_TIMESPEC if 'struct timespec' is declared
+dnl Check whether 'struct timespec' is declared
 dnl in time.h, sys/time.h, or pthread.h.
 
 AC_DEFUN([gl_CHECK_TYPE_STRUCT_TIMESPEC],
-- 
1.7.6.5